Everything worked fine until sequentce with the only element was passed to this function. The simplest way to reproduce is:
var sumOfSquares = Enumerable.Range(5, 1).Aggregate((s, i) => s + i*i);
// sumOfSquares == 5
I think this version of Aggregate should throw an Exception in case when sequence contains only one element.
Am I right or there is some details I missed ?
There’s another overload where you can provide an appropriate seed and obtain what I think is your desired result.
In this code, 0 is the initial seed,
sis the accumulated value,iis the current item. This produces the value 25.(5, 2)produces 61,(5, 3)produces 110, etc.