How To Iterate the Hashtable in C#
-
If we write in the same way as above for the hashtable then we would not get the desired values. Hashtable ss = new Hashtable(); ss["key1"] ="india"; ss["key2"] = "bharat"; foreach (object gg in ss) { Console.WriteLine("Key value is " + gg); Console.Read(); } Here we get System.Collections.DictionaryEntry and System.Collections.DictionaryEntry as output instead of the value pairs stored in the hashtable. In this case we can help of DictinaryEntry object for iterating the hashtable. foreach(DictionaryEntry gg in ss) { Console.WriteLine("Key and value are " + gg.Key + " " + gg.Value); Console.Read(); } A DictionaryEntry object is simply a container containing the Key and Value . http://www.mindfiresolutions.com/How-To-Iterate-the-Hashtable-in-C-311.php[^]
Cheers, Eliza
-
If we write in the same way as above for the hashtable then we would not get the desired values. Hashtable ss = new Hashtable(); ss["key1"] ="india"; ss["key2"] = "bharat"; foreach (object gg in ss) { Console.WriteLine("Key value is " + gg); Console.Read(); } Here we get System.Collections.DictionaryEntry and System.Collections.DictionaryEntry as output instead of the value pairs stored in the hashtable. In this case we can help of DictinaryEntry object for iterating the hashtable. foreach(DictionaryEntry gg in ss) { Console.WriteLine("Key and value are " + gg.Key + " " + gg.Value); Console.Read(); } A DictionaryEntry object is simply a container containing the Key and Value . http://www.mindfiresolutions.com/How-To-Iterate-the-Hashtable-in-C-311.php[^]
Cheers, Eliza
Did you post this in the wrong place? Perhaps you meant to post a tip/trick? Or maybe you meant to post this at the bottom of an article? This is a forum for C# questions.
-
Did you post this in the wrong place? Perhaps you meant to post a tip/trick? Or maybe you meant to post this at the bottom of an article? This is a forum for C# questions.
Nah, I think he just missed and gave us his lecture notes instead of his homework question... :laugh:
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
-
Nah, I think he just missed and gave us his lecture notes instead of his homework question... :laugh:
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
The link points to the same thing posted by the OP. I am honestlly baffled. :doh: