int sum0 = 0;
for (int i = 0; i < 10; i++)
{
sum0 += i;
}
int sum1 = Enumerable.Range(0, 10).Sum();
int sum2 = Enumerable.Range(0, 10).Aggregate((x, y) => x + y);
int sum3 = Enumerable.Range(0, 10).Aggregate(0, (x, y) => x + y);
All of the above 4 expressions are doing the same thing: find sum from 0 to 10. I understand the calculation of sum0 and sum1. But what are sum2 and sum3? Why the lambda uses two parameters (x, y) here?
Expanding on bdukes’ answer, the lambda takes
and sum3 allows you to set the initial x value.