Looping in a Hashtable
You can loop through the Hashtable in various ways (like a number of stuff in .NET). I will show two ...
-
private void loopWithEnumerator(Hashtable hashTable)
{
//Set the enumerator for the elements of the dictionary
IDictionaryEnumerator enumerator = hashTable.GetEnumerator();
//Loop into collection
while (enumerator.MoveNext())
{
Console.WriteLine("key : " + enumerator.Key.ToString());
Console.WriteLine("value : " + enumerator.Value.ToString());
}
}
-
private void loopWithDictionaryEntry(Hashtable hashTable)
{
//Loop into HashTable
foreach (DictionaryEntry dictionaryEntry in hashTable)
{
Console.WriteLine("key : " + dictionaryEntry.Key.ToString());
Console.WriteLine("value : " + dictionaryEntry.Value.ToString());
}
}
1 Comments:
At 5:58 PM, Anonymous said…
Thanks for the code! Came in handy!
Post a Comment
<< Home