tags:

views:

3049

answers:

3

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

+2  A: 

Use System.Linq.Enumerable.OrderByDescending() ?

For example:

var items = someEnumerable.OrderByDescending();
Brannon
+6  A: 

As Brannon says, it's OrderByDescending and ThenByDescending:

var query = from person in people
            order by 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);
Jon Skeet
+1  A: 

Try this:

List<int> list = new List<int>();
            list.Add(1);
            list.Add(5);
            list.Add(4);
            list.Add(3);
            list.Add(2);



            foreach (var item in list.OrderByDescending(x => x))
            {
                Console.WriteLine(item);                
            }