现在的位置: 首页 > 综合 > 正文

Hashtable的遍历

2013年04月16日 ⁄ 综合 ⁄ 共 391字 ⁄ 字号 评论关闭
两种方法:
1.DictionaryEntry
foreach( DictionaryEntry de in hashTable)
{
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();
}

抱歉!评论已关闭.