Understanding of Hashtable and arrylist in. Net

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.