D
damiensawyer
Hi, I have the following code extract...
---top---
List<Person> Persons = new List<Person>();
Persons.Add(new Person("Peter", 28,"Perth"));
Persons.Add(new Person("Matthew", 31, "Bundaberg"));
Persons.Add(new Person("Cathryn", 36, "Perth"));
//This works
IEnumerable<Person> p1 = from op in Persons
where op.City=="Perth"
select op;
//Tut this doesn't work
List<Person> p2 = from op in Persons
where op.City == "Perth"
select op;
---bottom---
The compiler error message is: Compiler Error Message: CS0266: Cannot
implicitly convert type
'System.Collections.Generic.IEnumerable<ASP.linq_linqgrouping_aspx.Person>'
to
'System.Collections.Generic.List<ASP.linq_linqgrouping_aspx.Person>'.
An explicit conversion exists (are you missing a cast?)
I'm trying to not get into the habit of using var because I read
somewhere (MSDN) that it makes your code more unreadable to others,
which I tend to agree with.
Can someone please tell me what I'm doing wrong?
Thanks in advance,
Damien
---top---
List<Person> Persons = new List<Person>();
Persons.Add(new Person("Peter", 28,"Perth"));
Persons.Add(new Person("Matthew", 31, "Bundaberg"));
Persons.Add(new Person("Cathryn", 36, "Perth"));
//This works
IEnumerable<Person> p1 = from op in Persons
where op.City=="Perth"
select op;
//Tut this doesn't work
List<Person> p2 = from op in Persons
where op.City == "Perth"
select op;
---bottom---
The compiler error message is: Compiler Error Message: CS0266: Cannot
implicitly convert type
'System.Collections.Generic.IEnumerable<ASP.linq_linqgrouping_aspx.Person>'
to
'System.Collections.Generic.List<ASP.linq_linqgrouping_aspx.Person>'.
An explicit conversion exists (are you missing a cast?)
I'm trying to not get into the habit of using var because I read
somewhere (MSDN) that it makes your code more unreadable to others,
which I tend to agree with.
Can someone please tell me what I'm doing wrong?
Thanks in advance,
Damien