I don't understand the order of execution in the following code. Here the numbers that satisfied the first Where
clause are (4, 10, 3, 7), and the numbers that satisfied the second Where
clause are 2 and 1, after that we have function Aggregate
that subtract them and make one element from both.
My question is what is the flow of execution here - (1) Where
is executed with c/3 > 0 for all the elements and after that (2) Where
or (1) first clause is executed for one element and its passed to (2) and from there to aggregate - when I print the values I cannot get value of x to be 28 on paper with both approaches also I cannot debug linq statement. Thanks for any help in advance.
var ints = new int[] { 2, 4, 1, 10, 3, 7 };
var x = ints
.Where(c => c / 3 > 0) <-- (1)
.Select(s2 => s2 + ints
.Where(c => c / 3 == 0) <-- (2)
.Aggregate((f, s) => f - s))
.Sum();