using System.Collections;
Code:
static void Main(string[] args)
{
Create an object of hash table
Hashtable myHash = new Hashtable();
Add key-pair values
myHash.Add("Saurabh", 1);
myHash.Add("Sandy", 2);
myHash.Add("Vivek", 3);
Move through hashtable data in cycle
foreach (DictionaryEntry item in myHash)
{
Console.WriteLine(item.Key);
Console.WriteLine(item.Value);
}
Get first item
Console.WriteLine("Get first item: " + myHash["Saurabh"]);
This will not work, name of item is not identical
Console.WriteLine("Get second item: " + myHash["Sandy"]);
}
0 comments:
Post a Comment