我使用在所呈現的支點方法: http://www.extensionmethod.net/Details.aspx?ID=147可空參數類型<T>爲通用方法?
我的問題是:如何使用可空類型作爲第二個通用密鑰?
public static Dictionary<TFirstKey, Dictionary<TSecondKey, TValue>> Pivot<TSource, TFirstKey, TSecondKey, TValue>(this IEnumerable<TSource> source, Func<TSource, TFirstKey> firstKeySelector, Func<TSource, TSecondKey> secondKeySelector, Func<IEnumerable<TSource>, TValue> aggregate) {
var retVal = new Dictionary<TFirstKey, Dictionary<TSecondKey, TValue>>();
var l = source.ToLookup(firstKeySelector);
//l.Dump("Lookup first key");
foreach (var item in l) {
var dict = new Dictionary<TSecondKey, TValue>();
retVal.Add(item.Key, dict);
var subdict = item.ToLookup(secondKeySelector);
foreach (var subitem in subdict) {
dict.Add(subitem.Key, aggregate(subitem));
}
}
return retVal;
}
什麼是您的編譯或運行時錯誤? – Spence 2011-01-11 09:33:40