In the following test:
int[] data = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
Func<int, int> boom = x => { Console.WriteLine(x); return x; };
var res = data.Select(boom).Skip(3).Take(4).ToList();
Console.WriteLine();
res.Select(boom).ToList();
The result is:
1
2
3
4
5
6
7
4
5
6
7
Essentially, I observed that in this example, Skip()
and Take()
work well, Skip()
is not as lazy as Take(). It seems that Skip()
still enumerates the items skipped, even though it does not return them.
The same applies if I do Take()
first. My best guess is that it needs to enumerate at least the first skip or take, in order to see where to go with the next one.
Why does it do this?