两种方法:
1.DictionaryEntry
2.IDictionaryEnumerator
1.DictionaryEntry
foreach( DictionaryEntry de in hashTable)
{
console.WriteLine("Key -- {0}; Value --{1}.", de.Key, de.Value);
}
{
console.WriteLine("Key -- {0}; Value --{1}.", de.Key, de.Value);
}
2.IDictionaryEnumerator
Hashtable food = new Hashtable();
IDictionaryEnumerator myEnumerator = food.GetEnumerator();
while(myEnumerator.MoveNext())
{
strfoodlist = strfoodlist + "\n\n" + myEnumerator.Key.ToString();
strfoodlist = strfoodlist + ":\t" +myEnumerator.Value.ToString();
}
IDictionaryEnumerator myEnumerator = food.GetEnumerator();
while(myEnumerator.MoveNext())
{
strfoodlist = strfoodlist + "\n\n" + myEnumerator.Key.ToString();
strfoodlist = strfoodlist + ":\t" +myEnumerator.Value.ToString();
}