I have a LINQ query:

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 list = from e in Employee orderby e.Name select e;

 

Please help me how to write correct query.



1 Answers

  1. Aditya Kumar Patel
    Re:LINQ query to select top three record from list
    9/26/2018 5:58:11 PM

    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 = (from e in Employee orderby e.Name select e).Take(3);

     

    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