For every single LINQ query I’ve written, I’ve always used a foreach loop to go through the result. Now, I have a program where I want to get the first 50 rows of the result, do some calculations with those rows, then get the next 50 rows of the result etc.
What is the good standards way to do this using LINQ and C#?
.Skip().Take() is going to be the best method (as far as clarity goes) in this case. For example:
It is worth noting that even though this seems more clear (you’re taking groups of 50 from the results), each time you call Skip() and Take() there’s a chance that the collection has to be enumerated over again…which is actually less efficient than simply using
foreachto enumerate over the results a single time.