Hashtable and arrylist in ASP. NET

Source: Internet
Author: User

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
Related Article

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.