Hi guys i want to convert employee collection to a List.

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 help me.

1 Answers

  1. Aditya Kumar Patel
    Re:ToList method in Linq Ankit Kumar
    9/28/2018 5:37:01 PM

    The ToList() method takes the elements from the given source and it returns a new List. So that means the input collection would be converted to type List.


    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 = "Rahul", ID = 5}};

     

                IEnumerable<Employee> result = Employee.ToList();

    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