Dictionary collections provide two additional properties: Keys and Values. Keys retrieves an ICollection object with all the keys in the Hashtable, as Values retrieves an ICollection object with all the values.
using System.Collections;
// Create and initialize a new Hashtable. Hashtable hashTable = new Hashtable( ); hashTable.Add("1", "AndhraPradesh"); hashTable.Add("2", "TamilNadu"); hashTable.Add("3", "Karnataka"); hashTable.Add("4", "Punjab"); // get the keys from the hashTable ICollection keys = hashTable.Keys; // get the values ICollection values = hashTable.Values; // iterate over the keys ICollection foreach(string key in keys) { Console.WriteLine("{0} ", key); } // iterate over the values collection foreach (string val in values) { Console.WriteLine("{0} ", val); }
OutPut: 1 2 3 4 AndhraPradesh TamilNadu Karnataka Punjab
|
No responses found. Be the first to respond and make money from revenue sharing program.
|