遍历HashTable的两种方法

方法一
 foreach (System.Collections.DictionaryEntry de in objHasTab)
{
    //注意HastTable内存储的默认类型是object,需要进行转换才可以输出
    Console.WriteLine(de.Key.ToString());
    Console.WriteLine(de.Value.ToString());
}

方法二
System.Collections.IDictionaryEnumerator enumerator = objHashTablet.GetEnumerator();
while (enumerator.MoveNext())
{
    Console.WriteLine(enumerator.Key);         // Hashtable关健字
    Console.WriteLine(enumerator.Value);      // Hashtable值
}

 

posted @ 2008-01-17 17:47  phcis  阅读(5507)  评论(1编辑  收藏  举报