Linq – OrderBy descending in Lambda expression

lambdalinq

I know in normal Linq grammar, orderby xxx descending is very easy, but how do I do this in Lambda expression?

Best Solution

As Brannon says, it's OrderByDescending and ThenByDescending:

var query = from person in people
            orderby person.Name descending, person.Age descending
            select person.Name;

is equivalent to:

var query = people.OrderByDescending(person => person.Name)
                  .ThenByDescending(person => person.Age)
                  .Select(person => person.Name);