Diligent achievement genius ...

业精于勤荒于嬉 行成于思毁于随 voiow博客
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

遍历Hashtable 的几种方法

Posted on 2007-09-30 12:02  voiow  阅读(165)  评论(0编辑  收藏  举报

 

using System.Collections;

            using System.Collections.Generic;

            Hashtable ht = new Hashtable();

            ht.Add("A", 1);

            ht.Add("B",2);

            //第一种方法:

            IDictionaryEnumerator enumerator = ht.GetEnumerator();

            while (enumerator.MoveNext)

            {

                Console.Write(enumerator.Key.ToString());

                Console.Write(enumerator.Value.ToString());

            }

            //第二种方法:

            foreach (DictionaryEntry objEnum in ht)

            {

                Console.Write(objEnum.Key.ToString());

                Console.Write(objEnum.Value.ToString());

            }