What is the best way to iterate over a dictionary?

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

    I found this method in the documentation for the DictionaryBase class on MSDN:

    foreach (DictionaryEntry de in myDictionary)
    {
         //Do some stuff with de.Value or de.Key
    }

    This was the only one I was able to get functioning correctly in a class that inherited from the DictionaryBase.

提交回复
热议问题