Enumerable.Aggregate 有 3 个重载版本。我找不到该函数的任何重载版本来匹配中使用的版本官方示例 https://msdn.microsoft.com/en-us/library/bb548651(v=vs.110).aspx.
public static TSource Aggregate<TSource>(
this IEnumerable<TSource> source,
Func<TSource, TSource, TSource> func
)
上面的定义与官方的例子完全不同:
string sentence = "the quick brown fox jumps over the lazy dog";
// Split the string into individual words.
string[] words = sentence.Split(' ');
// Prepend each word to the beginning of the
// new sentence to reverse the word order.
string reversed = words.Aggregate((workingSentence, next) =>
next + " " + workingSentence);
Console.WriteLine(reversed);
// This code produces the following output:
//
// dog lazy the over jumps fox brown quick the
以下是聚合函数的 3 个重载版本:
public static TSource Aggregate<TSource>(this IEnumerable<TSource> source, Func<TSource, TSource, TSource> func);
public static TAccumulate Aggregate<TSource, TAccumulate>(this IEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> func);
public static TResult Aggregate<TSource, TAccumulate, TResult>(this IEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> func, Func<TAccumulate, TResult> resultSelector);
它们都不与上面示例中使用的函数匹配。官方文档有错吗?或者我错过了什么?请帮助我弥合 3 个版本的函数定义和这个官方示例之间的差距。
如何理解函数定义?