Hashtable Concept in .Net

Provides a collection of key-value pairs that are organized
based on the hash code of the key.

Example:
static void Main()
{
Hashtable ht = new Hashtable(20);
ht.Add("ht01", "DotNetGuts");
ht.Add("ht02", "EasyTutor.2ya.com");
ht.Add("ht03", "DailyFreeCode.com");

Console.WriteLine("Printing Keys...");
foreach(string key in ht.Keys)
{
Console.WriteLine(key);
}

Console.WriteLine("\nPrinting Values...");
foreach(string Value in ht.Values)
{
Console.WriteLine(Value);
}

Console.WriteLine("Size of Hashtable is {0}", ht.Count);

Console.WriteLine(ht.ContainsKey("ht01"));
Console.WriteLine(ht.ContainsValue("DailyFreeCode.com"));

Console.WriteLine("\nRemoving element with key = ht02");
ht.Remove("ht02");

Console.WriteLine("Size of Hashtable is {0}", ht.Count);

}


Output

Printing Keys...
ht01
ht02
ht03

Printing Values...
DotNetGuts
EasyTutor.2ya.com
DailyFreeCode.com


Size of Hashtable is 3
True
True
 
Removing element with key = ht02
Size of Hashtable is 2

4 comments:

Amin said...

plz tell me the assembly reference for asp.net.....
Thanks

Amin said...

plz tell me the assembly reference for asp.net.....
Thanks

Divakar said...

System.Collections.Hashtable

Divakar said...

You can just use System.Collections

Most Recent Post

Most Recent Ado.net FAQ

Most Recent .Net Framework FAQ

Most Recent Configuration Files FAQ

Daily Quote, Inspiration, Motivation and More

Subscribe Blog via Email

Enter your email address: