If we write this for the hashtable then we would not get the desired values.
Here we get System.Collecti ons.DictionaryE ntry and System.Collecti ons.DictionaryE ntry as output instead of the value pairs stored in the hashtable.
In this case we can help of DictinaryEntry object for iterating the hashtable.
A DictionaryEntry object is simply a container containing the Key and Value .
Code:
Hashtable ss = new Hashtable();
ss["key1"] ="india";
ss["key2"] = "bharat";
foreach (object gg in ss)
{
Console.WriteLine("Key value is " + gg);
Console.Read();
}
In this case we can help of DictinaryEntry object for iterating the hashtable.
Code:
foreach(DictionaryEntry gg in ss)
{
Console.WriteLine("Key and value are " + gg.Key + " " + gg.Value);
Console.Read();
}
Comment