Copy Hashtable to Array instance at the specified index in CSharp
Description
The following code shows how to copy Hashtable to Array instance at the specified index.
Example
using System;//from ww w. j av a2 s .co m
using System.Collections;
class MainClass
{
public static void Main()
{
Hashtable myHashtable = new Hashtable();
myHashtable.Add("AL", "Alabama");
myHashtable.Add("CA", "California");
myHashtable.Add("FL", "Florida");
myHashtable.Add("NY", "New York");
myHashtable.Add("WY", "Wyoming");
string[] myKeys = new string[5];
myHashtable.Keys.CopyTo(myKeys, 0);
for (int counter = 0; counter < myKeys.Length; counter++) {
Console.WriteLine("myKeys[" + counter + "] = " + myKeys[counter]);
}
}
}
The code above generates the following result.