Hi, I have the following code extract...
---top---
List<PersonPers ons = 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<Per sonp1 = from op in Persons
where op.City=="Perth "
select op;
//Tut this doesn't work
List<Personp2 = 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.Collect ions.Generic.IE numerable<ASP.l inq_linqgroupin g_aspx.Person>'
to
'System.Collect ions.Generic.Li st<ASP.linq_lin qgrouping_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<PersonPers ons = 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<Per sonp1 = from op in Persons
where op.City=="Perth "
select op;
//Tut this doesn't work
List<Personp2 = 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.Collect ions.Generic.IE numerable<ASP.l inq_linqgroupin g_aspx.Person>'
to
'System.Collect ions.Generic.Li st<ASP.linq_lin qgrouping_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
Comment