Hashtable.CopyTo Method

   
Hashtable.CopyTo Method

Class

System.Collections.Hashtable

Syntax

   hashtablevariable   .CopyTo(   array   ,   arrayindex   ) 
array (required; Array of DictionaryEntry structures)

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

  • 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.

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 

See Also

Hashtable.Keys Property

   


VB.Net Language in a Nutshell
VB.NET Language in a Nutshell
ISBN: B00006L54Q
EAN: N/A
Year: 2002
Pages: 503

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net