Alex Rivera | Logout

C# - var to List<T> conversion

Asked 2009-10-11T17:49:09.680
10

How to cast/convert a var type to a List type?

This code snippet is giving me error:

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();
}
Edit
Report

1 Answer

3

You can call the ToList LINQ extension Method

List<Student> selectedCollection = selected.ToList<Student>();
foreach (Student s in selectedCollection)
{
    s.Show();
}
answered 2009-10-11T17:51:24.730

Your Answer