1
. HashtabelIn the. NET Framework, Hashtable is
System.Collectionsnamespace provides the
Collection Object,It is also a variable-length array that handles and behaves like a Key/value key-value pair, where key is usually used for quick lookups, while key is case-sensitive; value is used to store values corresponding to key. Key/value Key-value pairs in Hashtable are all object types, so hashtable can support any type of Key/value key-value pair:
simple operation of a hash tableAdd 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 (); Determines whether a hash table contains a specific key key:HashtableObject.Contains (key); such as: Hashtable ht=new Hashtable (); Ht.add (x,x) ...
traversing a hash tableTraversing a hash table requires the use of
DictionaryEntryObject with the following code: foreach (DictionaryEntry de in HT)//ht for a Hashtable instance {Console.WriteLine (DE. Key);//de. Key corresponds to the Key/value key value to key Console.WriteLine (DE. Value);//de. Key corresponds to Key/value value}
2. Arrylist (
array list)The ArrayList object is a variable-length array that can be added as needed. Use the ArrayList method to add elements to an array list, or to remove and modify an element. For example: ArrayList myarraylist = new ArrayList (); Myarraylist.add ("Caoxi"); Myarraylist.clear ();
The objects that are removed from the ArrayList are object types, which are converted to the appropriate type before use. ArrayList thearraylist = new ArrayList () Thearraylist.add ("1"); Thearraylist.add ("2"); string s = (string) thearraylist[ 0];string S1 = (string) thearraylist[1]; Note the Contains () method returns True if ArrayList contains the object supplied by the parameter, otherwise returns Falseif (Thearraylist.contains ("1"))//Determines whether the character "1" exists in the ArrayList
Understanding of Hashtable and arrylist in. Net