linq-groupBy


public static IEnumerable> GroupBy(this IEnumerable source, Func keySelector) {
            return new GroupedEnumerable(source, keySelector, IdentityFunction.Instance, null);
        }
 
        public static IEnumerable> GroupBy(this IEnumerable source, Func keySelector, IEqualityComparer comparer) {
            return new GroupedEnumerable(source, keySelector, IdentityFunction.Instance, comparer);
        }
 
        public static IEnumerable> GroupBy(this IEnumerable source, Func keySelector, Func elementSelector) {
            return new GroupedEnumerable(source, keySelector, elementSelector, null);
        }
 
        public static IEnumerable> GroupBy(this IEnumerable source, Func keySelector, Func elementSelector, IEqualityComparer comparer) {
            return new GroupedEnumerable(source, keySelector, elementSelector, comparer);
        }
 
       public static IEnumerable GroupBy(this IEnumerable source, Func keySelector, Func, TResult> resultSelector){
           return  new GroupedEnumerable(source, keySelector, IdentityFunction.Instance, resultSelector, null);
        }
 
        public static IEnumerable GroupBy(this IEnumerable source, Func keySelector, Func elementSelector, Func, TResult> resultSelector){
           return new GroupedEnumerable(source, keySelector, elementSelector, resultSelector, null);
        }
 
        public static IEnumerable GroupBy(this IEnumerable source, Func keySelector, Func, TResult> resultSelector, IEqualityComparer comparer){
            return  new GroupedEnumerable(source, keySelector, IdentityFunction.Instance, resultSelector, comparer);
        }
 
        public static IEnumerable GroupBy(this IEnumerable source, Func keySelector, Func elementSelector, Func, TResult> resultSelector, IEqualityComparer comparer){
            return  new GroupedEnumerable(source, keySelector, elementSelector, resultSelector, comparer);
        }

--其他方法

 public GroupedEnumerable(IEnumerable source, Func keySelector, Func elementSelector, Func, TResult> resultSelector, IEqualityComparer comparer){
            if (source == null) throw Error.ArgumentNull("source");
            if (keySelector == null) throw Error.ArgumentNull("keySelector");
            if (elementSelector == null) throw Error.ArgumentNull("elementSelector");
            if (resultSelector == null) throw Error.ArgumentNull("resultSelector");
            this.source = source;
            this.keySelector = keySelector;
            this.elementSelector = elementSelector;
            this.comparer = comparer;
            this.resultSelector = resultSelector;
        }

这个好像实现复杂,仔细分析下。