Copies the StringDictionary to an array with DictionaryEntry elements
Imports System
Imports System.Collections
Imports System.Collections.Specialized
Public Class SamplesStringDictionary
Public Shared Sub Main()
Dim myCol As New StringDictionary()
myCol.Add("red", "R")
myCol.Add("green", "G")
myCol.Add("blue", "B")
Dim myArr(myCol.Count) As DictionaryEntry
myCol.CopyTo(myArr, 0)
Dim i As Integer
For i = 0 To myArr.Length - 1
Console.WriteLine(" {0,-10} {1}", myArr(i).Key, myArr(i).Value)
Next i
End Sub
Public Shared Sub PrintKeysAndValues3(myCol As StringDictionary)
Dim myKeys(myCol.Count) As String
myCol.Keys.CopyTo(myKeys, 0)
Dim i As Integer
For i = 0 To myCol.Count - 1
Console.WriteLine(" {0,-5} {1,-25} {2}", i, myKeys(i), myCol(myKeys(i)))
Next i
End Sub
End Class
Related examples in the same category