I have the following code:
List<int> no = new List<int>() { 1, 2, 3, 4, 5 };
var res2 = no.Sum(a => a * a);
Console.WriteLine(res2);
no.Add(100);
Console.WriteLine(res2);
I expect the following result:
55
10055
but both are 55
55
55
I have seen here which is about deferred evaluation but was not helpful. Sum
is an extension method, but the result is not what I have mentioned. Why?