有3个Enumerable.Aggregate的过载版本。我无法找到该功能的任何过载版本以匹配official example中使用的版本。C#聚合函数定义说明
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个版本的函数定义和这个官方示例之间的差距。
如何理解函数定义?
实际上,你提到的第一个重载**与在“官方示例”中使用的相同。 – Evk
查看[扩展方法](https://msdn.microsoft.com/en-us/library/bb383977.aspx)。 –