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