How to convert LINQ query result to List?

Brillia picture Brillia · Apr 26, 2012 · Viewed 122.3k times · Source

I need to convert linq query result to list. I tried the following code:

var qry = from a in obj.tbCourses
                     select a;

List<course> lst = new List<course>();
lst = qry.ToList();

The following error occurred for the above code:

Cannot implicitly convert type 
System.Collections.Generic.List<Datalogiclayer.tbcourse> to
System.Collections.Generic.List<course>

Answer

dellgg picture dellgg · Nov 8, 2012

No need to do so much works..

var query = from c in obj.tbCourses
        where ...
        select c;

Then you can use:

List<course> list_course= query.ToList<course>();

It works fine for me.