»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 usesA 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
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.
|