Hashtable: a set of key/value pairs. These key/value pairs are organized according to the hash code of the key. In hashtable, keyValue pairs are of the object type, so hashtable can support any type of keyValue pairs.
Operations on the hash table include:
1. Add a keyValue pair
2. traverse the hash table
3. Sort hash tables
4. Determine whether a hash table contains a specific key. The return value is true or false.
5. Remove a keyValue pair
6. output values in the hash table
7. Remove all elements
Hashtable ht = new hashtable (); // 1. Add a keyValue pair to ht. add ("D", "DDD"); ht. add ("A", "AAA"); ht. add ("C", "CCC"); ht. add ("B", "BBB"); // 2. traverse the hash table foreach (dictionaryentry de in HT) {console. writeline ("key: {0}, value: {1}", de. key, de. value);} // 3. Sort the hash table. arraylist akeys = new arraylist (HT. keys); akeys. sort (); foreach (string key in akeys) {console. writeline ("sorted key: {0}, value: {1}", key, HT [Key]);} // 4. Determine whether the hash table contains a specific key, the return value is true or false if (HT. contains ("D") console. writeline (HT ["D"]); // 5. Remove a keyValue pair ht. remove ("C"); // 6. Output AAA console here. writeline (HT ["A"]); // 7. Remove all elements ht. clear (); // 8. No output console exists. writeline (HT ["A"]);