Hashtable.CopyTo Method |
System.Collections.Hashtable
hashtablevariable .CopyTo( array , arrayindex )
The destination of the items copied from the hash table
The first index that is to receive an element of the hash table
None
Copies the hash table values into an array of DictionaryEntry structures. A DictionaryEntry structure is a key/value pair. Note that the array must be sized to accommodate the elements of the hash table prior to calling the CopyTo method.
array must be a one-dimensional array.
Elements are copied from the hash table to array in the same order in which the hash table is iterated.
The CopyTo method copies each key/value pair in the hash table to a DictionaryEntry structure.
array , the array of DictionaryEntry structures, must be sized before calling the CopyTo method. This is illustrated in the example.
Dim hshStates As New Hashtable Dim aDE( ) As DictionaryEntry Dim oDE As DictionaryEntry hshStates.Add("NY", "New York") hshStates.Add("MI", "Michigan") hshStates.Add("CA", "California") hshStates.Add("WI", "Wisconsin") hshStates.Add("VT", "Vermont") hshStates.Item("WA") = "Washington" Redim aDE(hshStates.Count - 1) hshStates.CopyTo(aDE, 0) For each oDE in aDE Console.WriteLine(oDE.Key & ": " & oDE.Value) Next
Hashtable.Keys Property