扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:Ninputer 来源:论坛 2007年10月14日
关键字:
‘ Visual Basic .NET 8.0 代码 Private Sub btnConsumeGenerics_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConsumeGenerics.Click Dim employees As New Dictionary(Of String, Employee) Dim emp As Employee emp = New Employee emp.SSN = "111-11-1111" emp.FirstName = "Scott" emp.LastName = "Swigart" emp.Salary = 50000 employees.Add(emp.SSN, emp) Dim emp2 As Employee emp2 = employees.Item("111-11-1111") Dim s As String 's = employees.Item("111-11-1111") ' This is now a syntax error employees.Item("111-11-1111").LastName = "SomeoneElse" End Sub |
Dim employees As New Dictionary(Of String, Employee) |
's = employees.Item("111-11-1111") ' This is now a syntax error |
txtOutput.Text = "Performance" & vbCrLf Const iterations As Integer = 5000000 PerfTime.Start() Dim myArray(iterations) As Integer For i As Integer = 0 To iterations - 1 myArray(i) = i Next Dim elapsed As Integer = PerfTime.Stop txtOutput.Text &= "Array time: " & elapsed & vbCrLf myArray = Nothing GC.Collect() PerfTime.Start() Dim myArrayList As New ArrayList For i As Integer = 0 To iterations - 1 myArrayList.Add(i) Next elapsed = PerfTime.Stop txtOutput.Text &= "ArrayList time: " & elapsed & vbCrLf myArrayList = Nothing GC.Collect() PerfTime.Start() Dim myList As New List(Of Integer) For i As Integer = 0 To iterations - 1 myList.Add(i) Next elapsed = PerfTime.Stop txtOutput.Text &= "List time: " & elapsed & vbCrLf myList = Nothing GC.Collect() |
Private Sub Swap(Of ItemType)(ByRef v1 As ItemType, ByRef v2 As ItemType) Dim temp As ItemType temp = v1 v1 = v2 v2 = temp End Sub |
Swap(Of Integer)(v1, v2) |
Private Sub Swap(ByRef v1 As Integer, ByRef v2 As Integer) Dim temp As Integer temp = v1 v1 = v2 v2 = temp End Sub |
Swap(Of String)(v1, v2) |
Private Sub Swap(ByRef v1 As String, ByRef v2 As String) Dim temp As String temp = v1 v1 = v2 v2 = temp End Sub |
Private Sub btnSortIntegers_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSortIntegers.Click Dim ints(9) As Integer Dim r As New Random For i As Integer = 0 To 9 ints(i) = r.Next(1, 100) Next ' 冒泡排序 For j As Integer = 0 To 9 For k As Integer = 9 To 1 Step -1 If ints(k) < ints(k - 1) Then Swap(Of Integer)(ints(k), ints(k - 1)) End If Next Next txtOutput.Text = "Sort Integers" & vbCrLf For i As Integer = 0 To 9 txtOutput.Text &= ints(i) & vbCrLf Next End Sub |
Public Class SomeClass(Of ItemType) Private internalVar as ItemType Public Function SomeMethod(ByVal value As ItemType) As ItemType End Function End Class |
Public Class SomeClass(Of ItemType As IComparible) Public Function SomeMethod(ByVal value As ItemType) As ItemType End Function End Class |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者