ArrayList, Hashtable, List & lt; T & gt;, Dictionary & lt; K, V & gt;, arraylisthashtable

Source: Internet
Author: User

ArrayList, Hashtable, List <T>, Dictionary <K, V>, arraylisthashtable

1. ArrayList

ArrayList list = new ArrayList (); // for traversing for (int I = 0; I <list. count; I ++) {SE se SE = (SE) list [I]; Console. writeLine (se. name);} // foreach traverses foreach (Object obj in list) {SE se = (SE) list [I]; Console. writeLine (se. name );}

2. Hashtable

Hashtable list = new Hashtable (); // Hashtable cannot be accessed using indexes, so traversing a Hashtable can only use the foreache () method // traverse Keyforeach (Object obj in list. keys) {Console. writeLine (string) obj);} // traverse Valueforeach (Object obj in list. values) {SE se = (SE) obj; Console. writeLine (se. name);} // traverse at the same time. DictionaryEntry has a structure foreach (DictionaryEntry en in list) {Console. writeLine (se. keys); COnsole. writeLine (SE) en. value ). name );}

3. List <T>

// For traversal for (int I = 0; I <list. count; I ++) {// you do not need to convert the data type to Console. writeLine (list [I]);} // foreach traverses foreach (SE obj in list) {// The type conversion Console is not required for the duration. writeLine (obj );}//

4. Dictionary <K, V>

// Traverse Valuesforeach (SE se in list. values) {// you do not need to convert the data type to Console for the time duration. writeLine (se);} // traverse foreach (KeyValuePair <string, SE> en in list) {Console. writeLine (en. key); Console. writeLine (en. value. name);} // KeyValuePair <TKey, TValue> is a generic structure

 

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.