Introduction:

 

In this article we will learn, how to Skip method in LINQ or what is Skip method in LINQ C# Asp.net MVC with example.

Description:

In LINQ, Skip method is used to skips the specified number of elements starting from first element from the list or collection and returns the remaining elements from collection.  

 

Example of LINQ Skip() Method

 

Following is the example of using LINQ skip method to skip specified elements from collection and get remaining elements from collection.

 

using System;
using System.Collections.Generic;
using System.Linq;
namespace SQLTutorialsPoint
{
    class Employee
    {
        public string Name { get; set; }
        public int ID { get; set; }
    }
    class Program
    {
        static void Main(string[] args)
        {
            List<Employee> Employee = new List<Employee>(){
            new Employee() {  Name = "Suresh",ID  = 1},
            new Employee() {  Name = "Sekher", ID=  2 },
              new Employee() {  Name = "Sumit", ID=  3 },
            new Employee() {  Name = "Pankaj", ID = 4},
            new Employee() {  Name = "Suraj", ID = 5}};
 
            var result = Employee.Skip(2);
 
            foreach (var item in result)
            {
                Console.WriteLine("Employee Name:"+item.Name+"  ID:" +item.ID);
            }
 
            Console.ReadLine();
        }
    }
}

 

 

 

As you see above example, we are trying to skip the first two employees. So we passed “2” as an input parameter to the SKIP method. It will display the rest of the employees.

 

Now we will run and see the output.

 Use LINQ Skip Operator 

 

In this article we learned, how we can use LINQskip method / operator in method syntax and query syntax to skip some elements in list / collection and return remaining elements in sequence.

 

I hope it will help to you after reading.

comments


Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

You may also like