Mid From PDF LINQ LINQ

How to use LINQ to paginate and return total pages?

How to use LINQ to paginate and return total pages?

int pageSize = 2;

Follow :

int totalItems = employees.Count();

int totalPages = (int)Math.Ceiling(totalItems / (double)pageSize);

Console.WriteLine($"Total Pages: {totalPages}");

int pageNumber = 2;

var pageData = employees

.Skip((pageNumber - 1) * pageSize)

.Take(pageSize);

foreach (var emp in pageData)

Console.WriteLine(emp.Name);

More from LINQ Tutorial

All questions for this course
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details