例子,把一个 List<Dictionary<string, string>> 展开为 KeyValuePair 列表,结果会报错:
Error:解析表达式错误。
Oops! No applicable member has been found for the expression. The error occurred for expression "." at position 315 near ".SelectMany(d => d)
var dictList = new List<Dictionary<string, string>>
{
new Dictionary<string, string>()
{
{"key1", "value1"},
{"key2", "value2"}
},
new Dictionary<string, string>()
{
{"key3", "value3"},
{"key4", "value4"}
}
};
var mergedDict = dictList
.SelectMany(d => d)
.ToDictionary(kv => kv.Key, kv => kv.Value);