How to Perform Paging on a Collection with LINQ in C# ?

Below is a sample code snippet demonstrating how to perform paging on a collection with LINQ Query in C# using C# with the startindex and the number of records to be retreived.

How to Perform Paging on a Collection with LINQ in C# ?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GinktageConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            List<Employee> employee = new List<Employee>();
            employee.Add(new Employee { Name = "Senthil Kumar", Experience = 6 });
            employee.Add(new Employee { Name = "Naveen", Experience = 4 });
            employee.Add(new Employee { Name = "Praveen", Experience = 1 });
            int startIndex = 1;
            int count = 2;
            var query = (from i in employee
                         select i).Skip(startIndex).Take(count);
            Console.ReadLine();
        }
    }
    public class Employee
    {
        public string Name { get; set; }
        public int Experience { get; set; }
    }
}


image

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Hey, wait!Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.