What is the best way to iterate over a dictionary?

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

    If say, you want to iterate over the values collection by default, I believe you can implement IEnumerable<>, Where T is the type of the values object in the dictionary, and "this" is a Dictionary.

    public new IEnumerator GetEnumerator()
    {
       return this.Values.GetEnumerator();
    }
    

提交回复
热议问题