Mega Code Archive
0389 Unseeded aggregations
You can omit the seed value when calling Aggregate.
The first element becomes the implicit seed, and aggregation proceeds from the second element.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main()
{
int[] numbers = { 1, 2, 3 };
int x = numbers.Aggregate(0, (prod, n) => prod * n); // 0*1*2*3 = 0
int y = numbers.Aggregate((prod, n) => prod * n); // 1*2*3 = 6
Console.WriteLine(x);
Console.WriteLine(y);
}
}
The output:
0
6