1
我試圖使用下面的代碼把一個IEnumerable<KeyValuePair<string, object>>
成ILookup<string, object>
:IEnumerable的<T> .ToLookup <TKEY的,TValue>中
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(系統的定義。 Collections.Generic.IEnumerable, System.Func)」有一些無效參數
和
無法從'lambda表達式'轉換爲'System.Func'
我在做什麼錯誤的lambda表達式?
啊哈!謝謝,我從文檔沒有意識到第一個參數是* Source *類型 – Darbio