我想把一个 IEnumerable<KeyValuePair<string, object>>
转换成一个 ILookup<string, object>
,使用以下代码:
var list = new List<KeyValuePair<string, object>>()
{
new KeyValuePair<string, object>("London", null),
new KeyValuePair<string, object>("London", null),
new KeyValuePair<string, object>("London", null),
new KeyValuePair<string, object>("Sydney", null)
};
var lookup = list.ToLookup<string, object>(a => a.Key);
但编译器报错:
实例参数:无法从 'System.Collections.Generic.List>' 转换为 'System.Collections.Generic.IEnumerable'
还有
'System.Collections.Generic.List>' 不包含 'ToLookup' 的定义,最佳的扩展方法重载 'System.Linq.Enumerable.ToLookup(System.Collections.Generic.IEnumerable,System.Func)' 存在一些无效参数
以及
无法将 'lambda expression' 转换为 'System.Func'
我的 lambda 表达式哪里出了问题呢?