Dictionary<string,int> list =newDictionary<string,int>();
list.Add("d", 1);
//3.0以上版本
foreach(variteminlist)
{
Console.WriteLine(item.Key + item.Value);
}
//KeyValuePair<T,K>
foreach(KeyValuePair<string,int> kvinlist)
{
Console.WriteLine(kv.Key + kv.Value);
}
//通过键的集合取
foreach(stringkeyinlist.Keys)
{
Console.WriteLine(key + list[key]);
}
//直接取值
foreach(intvalinlist.Values)
{
Console.WriteLine(val);
}
//非要采用for的方法也可
List<string> test =newList<string>(list.Keys);
for(inti = 0; i < list.Count; i++)
{
Console.WriteLine(test[i] + list[test[i]]);
}