What is a hashtable

xiaoxiao2021-03-06  36

Excerpt from www.pconline.com.cn

I. Briefing the HashTable? In .NET Framework, HashTable is a container provided by System.Collections namespace, used to handle and behave like Key / Value key value, where KEY is usually available quickly At the same time, Key is case sensitive; VALUE is used to store values ​​corresponding to Key. The key / value key value in HashTable is an Object type, so HashTable can support any type of Key / Value key value pair.

Second, the bricked table simple operation? Add a Key / Value key value in the hash table: HashTableObject.add (key, value); "In the hash table, remove a Key / Value key value: HashTableObject. Remove (key); removes all the elements from the hash table: ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????. HashTableObject.contains (key) ;? The following console programs will contain all the above operations: use system; using system.collections; // When using HashTable, this namespace must be introduced into this namespace Class HashTable {? Public static void main ()? { ? Hashtable ht = new hashtable (); // Create a HashTable instance? HT.ADD ("e", "e"); // Add key / value key value? Ht.add ("a", "a" ) ;? Ht.Add ("c", "c") ;? HT.Add ("b", "b");

String s = (string) HT ["a"] ;? IF (HT.Contains ("e")) // Judging whether the hash table contains a specific key, its return value is true or false ??? console.writeline "THE E Key: EXIST") ;? Ht.Remove ("c"); // Remove a key / value key value? Console.WriteLine (HT ["A"]); // Output a? HT.clear (); // Remove all elements? Console.WriteLine (HT ["A"]); // Will there be any output?}}

Third, traverse the hash table? Traverse the hash of the table, you need to use DictionaryEntry Object, the code is as follows:? For (DictionaryTry de in HT) // HT is a HashTable instance? {?? console.writeLine (de.key); // De.key corresponds to the key ?? console.writeline (de.value); // de.key, corresponding to the key / value key value pair value?}

转载请注明原文地址:https://www.9cbs.com/read-116300.html

New Post(0)