Home | Articles|Namespace|Interview Questions|Tools|Jobs|Projects|Community
Asp.net Tutorials

»Dotnet Ads
»Message Boards
Message Boards
Dotnet Books

»Member Details
Register
Login
LogOut
Submit Code
Submit Jobs
Submit Projects

»Competition
Community
Winners
Prizes
Write For Us
Members

»Other Resources
Links
Dotnet Resources

c# HashTable and its uses

A HashTable allows you to do a fast search it works similar to a collection object. This small articles shows some of the features

Adding a object to a hastable


Hashtable ht = new Hashtable();

ht.Add("Key1", "Value1");
ht.Add("Key2", "Value2");


To check if a value or a key is in a hastable you use

ht.ContainsKey("Key1")

ht.ContainsValue("Value1")

To read a object from a hashtable you use

ht.Item("Key1")

Enumerating the Objects in the Hashtable

IDictionaryEnumerator iEnum = ht.GetEnumerator();

while (iEnum.MoveNext())
{
Console.WriteLine(iEnum.Key + " - " + iEnum.Value);
}


objects does not come out in the same way as you put them in a hastable. This is due to the hashing algorithm that keeps things running fast.

Have a Question and dont know the answer post it below and get answers in minutes

Due to spam this feature is disabled
To get answers fast , make sure you enter a detailed subject for example: "DataGrid issues need answer" not "DataGrid"

Subject:

Catjegory Name:

Message:



© 2008 dotnetwatch.com -- Privacy policy