dlmap

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

vb.net 也加入了范型,令人振奋,但是今天写了一个测试的例子,其结果,却让我失望不已

这叫什么啊~~~~

难道是我的代码有问题

  1Imports System
  2Imports System.Collections
  3Imports System.Collections.Generic
  4
  5Public Delegate Sub Method()
  6
  7Public Module VBGeneric
  8
  9    Sub Main()
 10        RunTest(New Test("ArrayList of string"AddressOf t1), _
 11        New Test("ArrayList of int"AddressOf t2), _
 12        New Test("List(Of String)"AddressOf t3), _
 13        New Test("List(Of Integer)"AddressOf t4))
 14        'Console.ReadLine()
 15    End Sub

 16
 17    Sub t1()
 18        Dim list As ArrayList = New ArrayList
 19        For i As Integer = 0 To 1000
 20            list.Add("hello")
 21            Dim str As String = CType(list(0), String)
 22            list.Remove(0)
 23        Next
 24    End Sub

 25
 26    Sub t2()
 27        Dim list As ArrayList = New ArrayList
 28        For i As Integer = 0 To 1000
 29            list.Add(123)
 30            Dim str As Integer = CType(list(0), Integer)
 31            list.Remove(0)
 32        Next
 33    End Sub

 34
 35    Sub t3()
 36        Dim list As List(Of String= New List(Of String)
 37        For i As Integer = 0 To 1000
 38            list.Add("hello")
 39            Dim str As String = list(0)
 40            list.Remove(0)
 41        Next
 42    End Sub

 43
 44    Sub t4()
 45        Dim list As List(Of Integer= New List(Of Integer)
 46        For i As Integer = 0 To 1000
 47            list.Add(123)
 48            Dim str As Integer = list(0)
 49            list.Remove(0)
 50        Next
 51    End Sub

 52
 53    Sub RunTest(ByVal ParamArray tests() As Test)
 54        For index As Integer = 0 To tests.Length - 1
 55            tests(index).m_code()
 56        Next
 57
 58        For index As Integer = 0 To tests.Length - 1
 59            Dim start As DateTime
 60            For m As Integer = 0 To 10
 61                tests(index).m_code()
 62            Next
 63            Dim time As TimeSpan = DateTime.Now - start
 64            DrawBar(index, time, tests(index).m_Name)
 65        Next
 66
 67    End Sub

 68
 69    Sub DrawBar(ByVal index As IntegerByVal time As TimeSpan, ByVal text As String)
 70
 71        Dim bg As ConsoleColor = Console.BackgroundColor
 72        Dim fg As ConsoleColor = Console.ForegroundColor
 73        If index Mod 2 = 0 Then
 74            Console.BackgroundColor = ConsoleColor.DarkBlue
 75        Else
 76            Console.BackgroundColor = ConsoleColor.DarkRed
 77        End If
 78        Console.ForegroundColor = ConsoleColor.White
 79        Dim size As Integer = Math.Min(CType((time.Milliseconds / 10), Integer), 79)
 80
 81        text = " " + text + " " + time.Milliseconds.ToString() + "ms"
 82
 83        For i As Integer = 0 To size
 84            Console.Write(" ")
 85        Next
 86        Console.WriteLine()
 87
 88        For i As Integer = 0 To size
 89            If i < text.Length Then
 90                Console.Write(text(i))
 91            Else
 92                Console.Write(" ")
 93            End If
 94
 95        Next
 96        Console.WriteLine()
 97
 98        For i As Integer = 0 To size
 99            Console.Write(" ")
100        Next
101
102        Console.WriteLine()
103        Console.WriteLine()
104        Console.BackgroundColor = bg
105        Console.ForegroundColor = fg
106    End Sub

107End Module

108
109Public Class Test
110
111    Public m_Name As String
112    Public m_code As Method
113
114    Public Sub New(ByVal name As StringByVal code As Method)
115        Me.m_Name = name
116        Me.m_code = code
117    End Sub

118
119End Class
posted on 2005-08-09 15:05  无色风  阅读(1486)  评论(10)    收藏  举报