I have written the below code in the .net core 3.1 console application. It's not working as expected.
var arr = new List<int>(Enumerable.Range(1, 10));
var last5 = arr.TakeLast(5);
foreach (var i in last5)
Console.WriteLine(i); //writing 6 7 8 9 10
arr.AddRange(new[] { 11, 12, 13, 14, 15 });
foreach (var i in last5)
Console.WriteLine(i); //writing 6 7 8 9 10 11
It is working as expected (6 7 8 9 10 11 12 13 14 15) If I target the project to in .net core 2.2.
I have used for loop for time being to solve the issue.
Why is it giving different values in .net core 2.2 and 3.1?