如何将var类型转换为List类型?
以下代码段给出了错误提示:
List<Student> studentCollection = Student.Get();
var selected = from s in studentCollection
select s;
List<Student> selectedCollection = (List<Student>)selected;
foreach (Student s in selectedCollection)
{
s.Show();
}
var
不是一种类型,它只是一个占位符,用于指定变量分配的表达式的类型。在这种情况下,查询表达式计算为IEnumerable<Student>
。 - Joren