难得有一片天

success.aspx?para1="要有决心"+para2="要努力"+para3="要有机会"
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Hashtable的遍历

Posted on 2007-10-15 21:37  seyon  阅读(494)  评论(0编辑  收藏  举报
两种方法:
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();
}