Use IDictionaryEnumerator to loop through a Hashtable in CSharp
Description
The following code shows how to use IDictionaryEnumerator to loop through a Hashtable.
Example
/* ww w.j a v a 2 s. com*/
using System;
using System.Collections;
public class IDicEnumDemo {
public static void Main() {
Hashtable ht = new Hashtable();
ht.Add("A", "555-3456");
ht.Add("B", "555-9876");
ht.Add("C", "555-3452");
ht.Add("D", "555-7756");
IDictionaryEnumerator etr = ht.GetEnumerator();
while(etr.MoveNext())
Console.WriteLine(etr.Entry.Key + ": " + etr.Entry.Value);
etr.Reset();
while(etr.MoveNext())
Console.WriteLine(etr.Key + ": " + etr.Value);
}
}
The code above generates the following result.