1
. HashtabelIn. NET Framework, hashtable is
System. CollectionsProvided by the namespace
Collection object,It is also a variable-length array used to process and display key-value pairs similar to key/value. The key is usually used for quick search, and the key is case sensitive; value is used to store the value corresponding to the key. In hashtable, key/value pairs are of the object type, so hashtable can support any type of key/value pairs ..
Simple operations on Hash TablesAdd a key/value Key-value pair to the hash table: hashtableobject. add (Key, value); remove a key/value Key-value pair in the hash table: hashtableobject. remove (key); remove all elements from the hash table: hashtableobject. clear (); checks whether the hash table contains the key hashtableobject. contains (key); for example: hashtable ht = new hashtable (); ht. add (×, × )... ...
Traverse a hash tableUsed to traverse a hash table
DictionaryentryObject, the Code is as follows: foreach (dictionaryentry de in HT) // HT is a hashtable instance {console. writeline (de. key); // de. the key corresponds to the key/value pair key console. writeline (de. value); // de. key corresponds to key/value Key-Value Pair value}
2. arrylist (
Array List)
The arraylist object is a variable-length array. You can add elements as needed. you can use the arraylist method to add or retrieve elements to the array list and modify an element. for example, arraylist myarraylist = new arraylist (); myarraylist. add (caoxi); myarraylist. clear ();
All objects retrieved from arraylist are of the object type. Before using arraylist, convert them to an appropriate type. arraylist thearraylist = new arraylist (); thearraylist. add (1); thearraylist. add (2); string S = (string) thearraylist [0]; string S1 = (string) thearraylist [1]; pay attention to contains () if arraylist contains objects provided by parameters, true is returned. Otherwise, falseif (thearraylist. contains (1) // determines whether character 1 exists in arraylist