I have a question about the efficiency of Skip()
and Take()
when used with IEnumerable<>
.
I am returning all my data lists with IEnumerable<>
and i use 'yield return' to prevent me from having to allocate large amounts of memory to pass back the data. This works very efficiently.
However, later in my process I wanted to batch this data and take blocks of say 20 entries from my list at a time. I thought to myself.. ah! This fits an enumerator perfectly.
I discovered the very useful Skip()
and Take()
methods on the IEnumerable interface
however I'm now realising that this causes my Loop to re-interate from the beginning each time.
What is the best way of paging data from an IEnumerable
? Am I better off using MoveFirst()
and MoveNext()
on the enumerator instead of Skip()
and Take()
?
I've done some googling but can't find an answer..
Can anyone help?
I really love LINQ
functionality on IEnumerable<>
however I really have to take efficiency into consideration.