What is the best way to iterate over a dictionary?

前端 未结 30 2213
我寻月下人不归
我寻月下人不归 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 06:04

    I will take the advantage of .NET 4.0+ and provide an updated answer to the originally accepted one:

    foreach(var entry in MyDic)
    {
        // do something with entry.Value or entry.Key
    }
    

提交回复
热议问题