Search code examples
c#linqlambdaanonymous-types

LINQ How to select more than 1 property in a lambda expression?


We often use the following lambda expression

MyList.Select(x => x.Id).ToList();

Is possible to get more than 1 property usinglambda expression ? E.g Id and Name from MyList?

I know that I can use the following syntax:

(from item in MyList
 select new { item.Id, item.Name }).ToList();

Can I do the same thing using lambda expression?


Solution

  • MyList.Select(x => new { x.Id, x.Name }).ToList();