
Hashtable遍历:
- Hashtable hashTable = new Hashtable();
- hashTable.Add("小张", "15975234395");
- hashTable.Add("小王", "15975234395");
- hashTable.Add("小芳", "15975234395");
- //遍历键值对
- foreach (DictionaryEntry item in hashTable)
- {
- Console.WriteLine(item.Key+","+item.Value);
- }
- //遍历所有Key
- foreach (string item in hashTable.Keys)
- {
- Console.WriteLine(item);
- }
-
- foreach (string item in hashTable.Values)
- {
- Console.WriteLine(item);
- }
评价