Why LINQ will work this way?

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:06 UTC
Read the original article Hit count: 345

Filed under:
|
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;
}

this doesn't compile: ArrayList is not IEnumerable

ArrayList lstStudents = GetStudentAsArrayList();
    var res = from r in lstStudents select r;  

but this will compile:

ArrayList lstStudents = GetStudentAsArrayList();
        var res = from  Student   r in lstStudents select r;

Can anybody explain? what's the magic here?

© Stack Overflow or respective owner

Related posts about c#

Related posts about LINQ