What is the best way to iterate over a dictionary?

前端 未结 30 1778
我寻月下人不归
我寻月下人不归 2020-11-22 05:18

I\'ve seen a few different ways to iterate over a dictionary in C#. Is there a standard way?

30条回答
  •  礼貌的吻别
    2020-11-22 05:55

    If you want to use for loop, you can do this:

    var keyList=new List(dictionary.Keys);
    for (int i = 0; i < keyList.Count; i++)
    {
       var key= keyList[i];
       var value = dictionary[key];
     }
    

提交回复
热议问题