1、ArrayList的遍历
foreach ( Object obj in myList ) { Console.Write( " {0}", obj ); }
2、Hashtable的遍历
for(DictionaryEntry de in ht) //ht为一个Hashtable实例 { Console.WriteLine(de.Key);//de.Key对应于key/value键值对key Console.WriteLine(de.Value);//de.Key对应于key/value键值对value }
3、List<T>的遍历
List<String> myList=new List<String>() foreach(String item in myList) { console.writelist(item); }
4、Dictionary<T,V>的遍历
Dictionary<string,string> openWith=new Dictionary<string,string>(); foreach( KeyValuePair<string, string> kvp in openWith ) { Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value); } Dictionary<string, string>.ValueCollection valueColl = openWith.Values; foreach( string s in valueColl ) { Console.WriteLine("Value = {0}", s); }