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()); } |