Write the syntax of foreach loop with hashtable and get the key, value pair from the hashtable?

 Posted by Peermohamedmydeen on 9/14/2010 | Category: C# Interview questions | Views: 4510 | Points: 40
Answer:

HashTable ht = new HashTable();
ht.Add(1,"A");
ht.Add(2,"B");
ht.Add(3,"C");

foreach(DictionaryEntry de in ht)
{
Console.WriteLine(string.Format("Key : {0} Value: {1}", de.Key.ToString(),de.Value.ToString()));

}


Asked In: Preliminary Technical Written Test | Alert Moderator 

Comments or Responses

Login to post response