Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从Ilist转换Linq查询<&燃气轮机;列出<&燃气轮机;_C#_Asp.net_Linq - Fatal编程技术网

C# 从Ilist转换Linq查询<&燃气轮机;列出<&燃气轮机;

C# 从Ilist转换Linq查询<&燃气轮机;列出<&燃气轮机;,c#,asp.net,linq,C#,Asp.net,Linq,我接收ILST数据,并将其存储如下: IList<Student> StudentList = DataKilde.Studenter(); 我收到一个转换错误,并尝试了以下操作: from s in (List<Student>)StudentList from s in StudentList as List<Student> 来自(列表)学生列表中的 从学生列表中的s作为列表 但它不起作用。。我不明白为什么?这是因为select s返回一个IQ

我接收
ILST
数据,并将其存储如下:

 IList<Student> StudentList = DataKilde.Studenter();
我收到一个转换错误,并尝试了以下操作:

from s in (List<Student>)StudentList

from s in StudentList as List<Student>
来自(列表)学生列表中的
从学生列表中的s作为列表

但它不起作用。。我不明白为什么?

这是因为
select s
返回一个
IQueryable
,它既不能隐式也不能显式转换为
列表,因为两者之间没有继承关系

您需要将查询结果具体化为一个列表:

(from s in StudentList
where s.StudentId==2
select s).ToList();

这将从源集合(
s
)中获取所有元素,并将它们存储在
列表中,该列表实现
IList

,这是因为
select s
返回一个
IQueryable
,该列表既不能隐式转换,也不能显式转换为
列表,因为两者之间没有继承关系

您需要将查询结果具体化为一个列表:

(from s in StudentList
where s.StudentId==2
select s).ToList();

这将从源集合(
s
)中获取所有元素,并将它们存储在
列表中,该列表实现了
IList

LINQ查询返回的
IEnumerable
不是
列表。将其存储在变量
var query=…
中,然后调用
List studentWhere5=query.ToList()
LINQ查询返回的
IEnumerable
不是
列表
。将其存储在变量
var query=…
中,然后调用
List studentWhere5=query.ToList()
(from s in StudentList
where s.StudentId==2
select s).ToList();