I have the following code:
List<int> nums = new List<int>();
nums.Add(1);
nums.Add(4);
nums.Add(2);
var lowNums = from n in nums
where n%2==0
select n;
Console.WriteLine("Even Numbers before adding 20 :");
foreach (var x in lowNums)
{
Console.WriteLine(x);
}
nums.Add(20);
Console.WriteLine("Even Numbers after adding 20:");
foreach (var x in lowNums)
{
Console.WriteLine(x);
}
Here while running this,it gives me this output:
.
But I wonder why it shows 20 because I am not running the LINQ expression after I add 20. I just display the previously calculated result. Can anyone explain this?