Hashtable.CopyTo Method


Hashtable.CopyTo Method

Class

System.Collections.Hashtable

Syntax

     hashtableVariable.CopyTo(array, arrayIndex) 


array (required; array of DictionaryEntry )

Array to which to copy the hashtable's key/value pairs


arrayIndex (required; Integer)

The index of the first zero-based array element to receive a hashtable pair.

Description

The CopyTo method copies hashtable key/value pairs into an existing array, starting at a specified array index. The array must use the DictionaryEntry structure for its type; this structure includes members for both keys and values.

Usage at a Glance

  • The array must be sized to accommodate the elements of the hashtable prior to calling the CopyTo method.

  • Elements are copied from the hashtable to array in the same order in which the hashtable is iterated.

Example

The sample code copies hashtable pairs to an array.

     Dim nameTable As New Hashtable     Dim stateArray(  ) As DictionaryEntry     ' ----- Build the hashtable.     nameTable.Add("Ch", "Chopin")     nameTable.Add("Mo", "Mozart")     nameTable.Add("Be", "Beethoven")     ReDim stateArray(nameTable.Count - 1)     nameTable.CopyTo(stateArray, 0) 

See Also

Hashtable Class, Hashtable.Keys Property




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

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