Now I want to get list of Employee but skip first 2 Employee. So if I have say for e.g. 5  Employee then I want to get 3 - 5 Employee and skip Employee 1 and 2.

This is employee list:

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 }};

 

Please give me correct query

1 Answers

  1. Aditya Kumar Patel
    Re:How to skip first 2 records and get all other records in LINQ Ankit Kumar
    9/27/2018 7:01:07 PM

    Skip() returns all remaining elements as ienumerable. therefore you can use


    Try to use it:

    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);

    It will 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.

    I hope it will help to you.


Leave a answer

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

You may also like