views:

554

answers:

3

Is there any difference at all between this:

dataContext.People.Select(ø => new
{
     Name = ø.Name,
});

and this:

dataContext.People.Select(ø => new
{
     ø.Name,
});

?

+3  A: 

They are identical; if no name is specified (and the right-hand-side is a simple member-access) then the name of the existing member is assumed. The name is only necessary to:

  • change the name to something else (for example Name = grp.Key)
  • to give a name to a non-member-access expression (for example Count = grp.Count())
Marc Gravell
haha too fast :P
Kelly
on his reputation, it looks like he has some practice :p
Svish
+1  A: 

No. The second simply derives the name of the property for you, the actual code generated is the same.

AnthonyWJones
+1  A: 

No, the compiler will name the property of the anonymous type the same as the right hand side of the assignment.

Frans Bouma