Dictionary 的几种遍历方法
Dictionary<string, int>dic = newDictionary<string, int>();
方法1 foreach (var item in dic) { Console.WriteLine(dic.Key + dic.Value); } 方法2 //KeyValuePair<T,K> foreach (KeyValuePair<string, int> kv in dic) { Console.WriteLine(kv.Key + kv.Value); } 方法3 //通过键的集合取 foreach (string key indic.Keys) { Console.WriteLine(key + list[key]); }