VB.NET 中的2种集合

   //在  .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

 

 

 

 

 

 

 

posted on 2011-09-26 14:37  风尘女子  阅读(246)  评论(0编辑  收藏  举报

导航