Hashtable.CopyTo Method copies the Hashtable elements to a one-dimensional Array instance at the specified index.
using System;
using System.Collections;
public class SamplesHashtable {
public static void Main() {
Hashtable mySourceHT = new Hashtable();
mySourceHT.Add( "A", "valueA" );
mySourceHT.Add( "B", "valueB" );
String[] myTargetArray = new String[15];
myTargetArray[0] = "The";
myTargetArray[1] = "quick";
myTargetArray[2] = "brown";
myTargetArray[3] = "fox";
myTargetArray[4] = "jumped";
myTargetArray[5] = "over";
myTargetArray[6] = "the";
myTargetArray[7] = "lazy";
myTargetArray[8] = "dog";
mySourceHT.Keys.CopyTo( myTargetArray, 6 );
PrintValues( myTargetArray, ' ' );
mySourceHT.Values.CopyTo( myTargetArray, 6 );
PrintValues( myTargetArray, ' ' );
}
public static void PrintValues( String[] myArr, char mySeparator ) {
for ( int i = 0; i < myArr.Length; i++ )
Console.Write( "{0}{1}", mySeparator, myArr[i] );
Console.WriteLine();
}
}
Related examples in the same category