OrderedDictionary Class represents a collection of key/value pairs that are accessible by the key or index. : OrderedDictionary « Data Structure « VB.Net






OrderedDictionary Class represents a collection of key/value pairs that are accessible by the key or index.

 

Imports System
Imports System.Collections
Imports System.Collections.Specialized

Public Class OrderedDictionarySample
    Public Shared Sub Main()
        Dim myOrderedDictionary As New OrderedDictionary()
        myOrderedDictionary.Add("testKey1", "testValue1")
        myOrderedDictionary.Add("testKey2", "testValue2")

        Dim keyCollection As ICollection = myOrderedDictionary.Keys
        Dim valueCollection As ICollection = myOrderedDictionary.Values

        DisplayContents(keyCollection, valueCollection, myOrderedDictionary.Count)
    End Sub
    Public Shared Sub DisplayContents(ByVal keyCollection As ICollection,ByVal valueCollection As ICollection, ByVal dictionarySize As Integer)
        Dim myKeys(dictionarySize) As [String]
        Dim myValues(dictionarySize) As [String]
        keyCollection.CopyTo(myKeys, 0)
        valueCollection.CopyTo(myValues, 0)

        Dim i As Integer
        For i = 0 To dictionarySize - 1
            Console.WriteLine("   {0,-5} {1,-25} {2}", _
                 i, myKeys(i), myValues(i))
        Next i
    End Sub
End Class

   
  








Related examples in the same category

1.Displays the contents of the OrderedDictionary using its enumerator