1

I have a grid with pager, I am trying to get the next 25 records starting with a start index.

for example for the first time it I return 25 records, when I change to next I want to pick the next 25 records and skip the first 25.

What is the most preferable way to do it using LINQ?

Thanks, Alaa

Alaa Osta
  • 4,249
  • 6
  • 24
  • 28
  • I think that is the best approach I got to, uvs = uvs.Skip(startIndex.Value * recordsCount.Value).Take(recordsCount.Value); is there any better solution for performance? – Alaa Osta May 09 '12 at 15:40

2 Answers2

5

I would use use the Take and Skip methods

var list = source.Skip(25 * page).Take(25);
Aducci
  • 26,101
  • 8
  • 63
  • 67
0

If you want better performance, you can partition your collection of records into groups of 25: here's a simple solution and an efficient solution.

Remember that each time an IEnumerable gets enumerated, the statement that created it gets executed, so be sure to use ToList() when appropriate.

Community
  • 1
  • 1
Risky Martin
  • 2,491
  • 2
  • 15
  • 16