Convert dictionary values to list using linq

后端 未结 2 1298
北恋
北恋 2020-12-30 19:56

Following code giving me \'Evaluation of lambda expressions is not valid in the debugger\'. Please suggest where I am doing wrong from below -

List

        
相关标签:
2条回答
  • 2020-12-30 20:28

    You will get a compiler error simply trying to convert a dictionary's values to a list with ToList():

            Dictionary<int, int> dict = new Dictionary<int, int>();
            var result = dict.Values.ToList();
    

    Unless you include "using System.Linq" in your file.

    0 讨论(0)
  • 2020-12-30 20:31

    You don't need to use Linq to get the values. The Dictionary(TKey, TValue) has a property that holds the values, Dictionary(TKey, TValue).Values:

    var fields = objDictionary.Values.ToList();
    
    0 讨论(0)
提交回复
热议问题