Convert LINQ Query to List

Introduction

In this blog we will see how LINQ query result can be converted into list and later how the list can be consumed according to the any requirement perspective.

Step 1: Create console application

application

Program.cs

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Threading.Tasks;  
  6.   
  7. namespace Convert_LINQ_Query_to_List  
  8. {  
  9.     class Program  
  10.     {  
  11.           
  12.         static void Main(string[] args)  
  13.         {  
  14.             SchoolManagementEntities objSchoolManagementEntities = new SchoolManagementEntities();  
  15.             var query = from r in objSchoolManagementEntities.Students select r;  
  16.             List<Student> lstStudents = query.ToList();  
  17.         }  
  18.     }  
  19. }  

Output of the application looks like this

output

Summary

In this blog we have seen how LINQ Query can be converted into list. Happy coding!

Ebook Download
View all
Learn
View all
MVC Corporation is consulting and IT services based company.