Search results for 'Hash'. 1 post(s) found.
- 2007/08/27 HashTable Tutorial In C#
Adding objects to a Hashtable is just like adding to a collection since they both inherit from the same parent.
Hashtable h = new Hashtable();
h.Add("Key1", "Value1");
h.Add("Key2", "Value2");
h.Add("Key3", "Value3");
h.Add("Key4", "Value4");
h.Add("Key5", "Value5");
h.Add("Key1", "Value1");
h.Add("Key2", "Value2");
h.Add("Key3", "Value3");
h.Add("Key4", "Value4");
h.Add("Key5", "Value5");
Determining if an Object is in the Hashtable
You can search the Key and the Value lists in a Hashtable for a specific entry:
Here is an example of checking the Key list:
Console.WriteLine(h.ContainsKey("Key5"))
Here is an example of checking the Value list:
Console.WriteLine(h.ContainsValue("Value2"));
Reading an Object in the Hashtable
To read an object from the Hashtable just use the Item method like so:
Console.WriteLine(h.Item("Key3"));
Enumerating the Objects in the Hashtable
One thing to remember is that the objects may not come out of the Hashtable in the same order as you put them in. This is due to the Hashing algorithm that keeps things running fast.
IDictionaryEnumerator en = h.GetEnumerator();
while (en.MoveNext())
{
Console.WriteLine(en.Key " : " en.Value);
}
while (en.MoveNext())
{
Console.WriteLine(en.Key " : " en.Value);
}
Another posts included in "C#"
| Calling Your Main Thread From A Worker Thread In C# (0) | 2007/08/27 |
| Creating A Watched Folder With Assigned Events (0) | 2007/08/27 |
| Interacting With TinyPic From C# (0) | 2007/08/27 |
| Stack Tutorial In C# (0) | 2007/08/27 |
| Queue Tutorial In C# (0) | 2007/08/27 |
| Create PDF Files On the Fly In C Sharp (0) | 2007/08/27 |
| How to call Visual C/C++ implemented DLL functions in C# - Simple DLLIm... (0) | 2007/08/26 |
| Send Email Using C# (0) | 2007/08/26 |
Trackback : Cannot send a trackbact to this post.
-
Subject different money making ideas
2010/01/29 02:43
moneyideas
-
Subject different money making ideas
2010/01/29 11:22
moneyideas
-
Subject different money making ideas
2010/01/31 16:44
moneyideas

Prev

Rss Feed