// 无序的键值表(以键的顺序来排列)
Hashtable hashTable = new Hashtable();
hashTable["a"] = 1;
hashTable["b"] = 2;
hashTable["c"] = 3;
hashTable["d"] = 4;
hashTable["e"] = 5;
hashTable["f"] = "cxm";
foreach (DictionaryEntry item in hashTable)
{
Console.WriteLine("key:{0}, value:{1}", item.Key, item.Value);
}
// 有序的键值表(以键的顺序来排列)
SortedList sortList = new SortedList();
sortList["a"] = 1;
sortList["c"] = 2;
sortList["b"] = 3;
sortList["d"] = 4;
sortList["e"] = 5;
sortList["f"] = "cxm";
foreach (DictionaryEntry item in sortList)
{
Console.WriteLine("key:{0}, value:{1}", item.Key, item.Value);
}
Console.ReadLine();
|