Hashtable.Values.CopyTo : HashTable « System.Collections « C# / C Sharp by API






Hashtable.Values.CopyTo

  
using System;
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");

    foreach (string myKey in myHashtable.Keys)
    {
      Console.WriteLine("myKey = " + myKey);
    }
    foreach(string myValue in myHashtable.Values)
    {
      Console.WriteLine("myValue = " + myValue);
    }
    
    Console.WriteLine("Copying values to myValues array");
    string[] myValues = new string[5];
    myHashtable.Values.CopyTo(myValues, 0);
    for (int counter = 0; counter < myValues.Length; counter++)
    {
      Console.WriteLine("myValues[" + counter + "] = " + myValues[counter]);
    }
  }
}

   
    
  








Related examples in the same category

1.HashTable.Keys
2.HashTable.Remove
3.Hashtable.Add
4.Hashtable.ContainsKey
5.Hashtable.ContainsValue
6.Hashtable.Keys.CopyTo
7.Hashtable.Synchronized
8.Hashtable.Values