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]);
}

 

相关文章:

  • 2022-12-23
  • 2022-03-09
  • 2021-05-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-20
  • 2021-06-26
相关资源
相似解决方案