//HashTable类表示一个键(Key)/值(Value)对的集合根据指定的键的哈希代码来组织这些键/值对 //示例: using System; using SystemCollectionsGeneric; using SystemText; using SystemCollections; using SystemData; namespace ConsoleApplication { public class ContractorTest { public static void Main() { Hashtable currencies = new Hashtable(); currenciesAdd(US Dollar); currenciesAdd(Japan Yen); currenciesAdd(France Euro); ConsoleWrite(US Currency: {} currencies[US]); ConsoleReadLine(); } } } //示例: using System; using SystemCollectionsGeneric; using SystemText; using SystemCollections; using SystemData; namespace ConsoleApplication { public class ContractorTest { public static void Main() { student stu = new student(); stuStuid = ; stuStrname = zhangsan; student stu = new student(); stuStuid = ; stuStrname = lisi; Hashtable ht = new Hashtable(); htAdd(stuStuid stu); htAdd(stuStuid stu); //第一种方法遍历集合中元素不通用 //for (int i = ; i < htCount + ; i++) //{ // student stu = (student)ht[i]; // ConsoleWriteLine(stuStuidToString() + + stuStrname); //} //第二种方法遍历集合中元素 IDictionaryEnumerator ide = htGetEnumerator(); while (ideMoveNext()) { DictionaryEntry destu = (DictionaryEntry)ideCurrent; //ConsoleWriteLine(destuKeyToString()); student stu = (student)destuValue; ConsoleWriteLine(stuStuid + + stuStrname); } ConsoleReadLine(); } } |