Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Home » Tip Bank » .NET » C#
Language: .NET
Expertise: Intermediate
Oct 14, 2019

Use LINQ Methods to Implement Paging in C#

With the Skip and Take methods in LINQ, paging has become a lot easier.

All we need to do is have a simple logic such as is outlined below. This will provide the paged items.

var pagedItems = theListWithLotsOfItems.Skip ((pageNumber - 1) * pageSize).Take(pageSize);

pageNumber(1) and pageSize(10) will provide first 10 items, and pageNumber(2) and pageSize(10) will provide second page data - another 10 items and so on.
Srinath M S
Thanks for your registration, follow us on our social networks to keep up-to-date