【发布时间】:2012-11-28 04:16:29
【问题描述】:
我正在尝试使用以下代码将 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 表达式”转换为“System.Func”
我对 lambda 表达式做错了什么?
【问题讨论】: