Name
Hashtable.CopyTo Method
Class
System.Collections.Hashtable
Syntax
hashtablevariable.CopyTo(array,arrayindex)
-
array(required; Array ofDictionaryEntrystructures) The destination of the items copied from the hash table
-
arrayindex(required; Integer) The first index that is to receive an element of the hash table
Return Value
None
Description
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.
Rules at a Glance
arraymust be a one-dimensional array.Elements are copied from the hash table to
arrayin the same order in which the hash table is iterated.The CopyTo method copies each key/value pair in the hash table to a
DictionaryEntrystructure.array, the array ofDictionaryEntrystructures, must be sized before calling the CopyTo method. This is illustrated in the example.
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)
NextSee Also
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access