Several ways to traverse Hashtable
- 2020-05-05 11:43:56
- OfStack
Method 1:
IDictionaryEnumerator enumerator = thProduct.GetEnumerator();
while (enumerator.MoveNext())
{
arrKey.Add ("@"+ enumerator.Key.ToString ()); // Hashtable
arrValue Add(enumerator Value ToString()); // Hashtable
}
Method 2:
using System.Collections;
HashTable objHasTab;
// Setting values to objHasTab
foreach (DictionaryEntry objDE in objHasTab)
{
Console.WriteLine(objDE.Key.ToString());
Console.WriteLine(objDE.Value.ToString());
}
IDictionaryEnumerator enumerator = thProduct.GetEnumerator();
while (enumerator.MoveNext())
{
arrKey.Add ("@"+ enumerator.Key.ToString ()); // Hashtable
arrValue Add(enumerator Value ToString()); // Hashtable
}
Method 2:
using System.Collections;
HashTable objHasTab;
// Setting values to objHasTab
foreach (DictionaryEntry objDE in objHasTab)
{
Console.WriteLine(objDE.Key.ToString());
Console.WriteLine(objDE.Value.ToString());
}