How To Iterate the Hashtable in C#

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 .
[code] http://www.mindfiresolutions.com/How-To-Iterate-the-Hashtable-in-C-311.php[/code]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories