In this article we will learn, how to AsEnumerable() method in LINQ or what is AsEnumerable() method in LINQ C# MVC with example.


In LINQ, AsEnumerable() method is used to cast or convert specific type of given list items to As IEnumerable<T>.

Example of LINQ AsEnumerable() Method

Following is the example of using LINQ AsEnumerable method to convert list of items to As IEnumerable<T> type.

 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 = "Rahul", ID = 5}};
           IEnumerable<Employee> result = Employee.AsEnumerable();
            foreach (var item in result)
                Console.WriteLine(" ID:" + item.ID +"Name:"+item.Name);               


As you see observe above array we are converting “employee” list to IEnumerable type by using AsEnumerable() method.


Now we will run and see the output.

 Use LINQ AsEnumerable() Method

In this article we learned, how we can use LINQ AsEnumerable() method to convert list of items to IEnumerable list.


I hope it will help to you after reading.



Leave a comment

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

You may also like