//在 .NET种又2种集合 一种是 VB的 collection 集合 另一种是 .NET Framework 的泛型集合
////VB的collection集合 和 .NET下的泛型集合 泛型集合限定了 键值对的类型
1. VB的collection集合
Module Module1
Sub Main()
Dim col As New Microsoft.VisualBasic.Collection()
col.Add(1, "firstkey")
col.Add(2, "secondkey")
col.Add(3, "thirdkey")
Dim num As Integer
num = col.Count
Dim a As Integer
For a = 1 To num
Console.WriteLine(col.Item(a).ToString()) //VB的 collection集合
Next
MsgBox("")
End Sub
End Module
2. .NET 的Dicoionary 泛型集合 KeyValuePair键值对类型 可以用for each ....next 语句来遍历 泛型集合 元素 下面是代码
Module Module1
Sub Main()
Dim col As New Dictionary(Of String, String)
col.Add("1", "item1")
col.Add("2", "item2")
col.Add("3", "item3")
col.Add("4", "item4")
Dim aPair As KeyValuePair(Of String, String)
For Each aPair In col
Console.WriteLine(aPair.Key + Space(2) + aPair.Value)
Next
MsgBox("")
End Sub
End Module
本文对比了VB的collection集合与.NET框架下的泛型集合,解释了两者的特点及使用方式,包括VB集合的简单操作与.NET泛型集合中键值对类型的限定和遍历方法。
168

被折叠的 条评论
为什么被折叠?



