To add to what Estys has - rightly - said ...
When you use
select new
in a Linq query, it creates an
anonymous type
unless you explicitly specify the name of an existing type:
var x = (from p in ...
select new
{
X = p.x,
Y = P.y
}).ToList();
var y = (from p in ...
select new MyClass()
{
X = p.x,
Y = P.y
}).ToList();
The former create a list of an anonymous class, the second creates a list of MyClass objects. Even though the two classes contain identical data, and identical properties, the system cannot and will not consider them the same: MyClass could have methods delegates, events, fields, or even properties that are not a part of the anonymous type and so the two collections are not equivalent, and the anonymous type collection cannot be assigned to a variable of the named class collection.