使用linq将字典值转换为列表
下面的代码给我“lambda表达式的评估在调试器中无效”。 请从下面建议我做错的地方 –
List lstFiedls; lstFiedls = objDictionary.Select(item => item.Value).ToList();
谢谢,
您不需要使用Linq来获取值。 Dictionary(TKey, TValue)
有一个属性,它包含值, Dictionary(TKey, TValue).Values
:
var fields = objDictionary.Values.ToList();
只需尝试将字典的值转换为带有ToList()的列表,您将收到编译器错误:
Dictionary dict = new Dictionary(); var result = dict.Values.ToList();
除非您在文件中包含“using System.Linq”。