復制代碼 代碼如下:
Dictionary<string,string> list=new Dictionary<string,string>;
//3.0以上版本
foreach(var item in list)
{
Console.WriteLine(item.Key+item.Value);
}
//KeyValuePair<T,K>
foreach(KeyValuePair<string,string> kv in list)
{
Console.WriteLine(kv.Key+kv.Value);
}
//通過鍵的集合取
foreach(string key in list.Keys)
{
Console.WriteLine(key+list[key]);
}
//for循環遍歷
List<string> test=new List<string>(list.Keys);
for(int i=0;i<list.Count;i++)
{
Console.WriteLine(test[i]+list[test[i]]);
}