LINQ: why does this query not work on an ArrayList?
Posted
by Benny
on Stack Overflow
See other posts from Stack Overflow
or by Benny
Published on 2010-03-16T05:00:50Z
Indexed on
2010/03/16
5:16 UTC
Read the original article
Hit count: 317
public static ArrayList GetStudentAsArrayList()
{
ArrayList students = new ArrayList
{
new Student() { RollNumber = 1,Name ="Alex " , Section = 1 ,HostelNumber=1 },
new Student() { RollNumber = 2,Name ="Jonty " , Section = 2 ,HostelNumber=2 }
};
return students;
}
The following code doesn't compile. The error is ArrayList is not IEnumerable
ArrayList lstStudents = GetStudentAsArrayList();
var res = from r in lstStudents select r;
This compiles:
ArrayList lstStudents = GetStudentAsArrayList();
var res = from Student r in lstStudents select r;
Can anybody explain what the difference is between these two snippets? Why the second works?
© Stack Overflow or respective owner