如何将LINQ查询结果转换为List? [英] How to convert LINQ query result to List?

查看:118
本文介绍了如何将LINQ查询结果转换为List?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将linq查询结果转换为列表.我尝试了以下代码:

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>

推荐答案

无需做太多工作..

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

然后您可以使用:

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

对我来说很好.

这篇关于如何将LINQ查询结果转换为List?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆