What is the best way to iterate over a dictionary?

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

    simple with linq

     Dictionary dict = new Dictionary();
     dict.Add(1, "American Ipa");
     dict.Add(2, "Weiss");
     dict.ToList().ForEach(x => Console.WriteLine($"key: {x.Key} | value: {x.Value}") );
    

提交回复
热议问题