OrderBy以Lambda表达式降序?

我知道在正常的Linq语法中, orderby xxx descending很容易,但我如何在Lambda表达式中执行此操作?


正如Brannon所说,它是OrderByDescendingThenByDescending

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

相当于:

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

使用System.Linq.Enumerable.OrderByDescending()

例如:

var items = someEnumerable.OrderByDescending();

尝试这个:

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);                
}
链接地址: http://www.djcxy.com/p/90343.html

上一篇: OrderBy descending in Lambda expression?

下一篇: How do I use reflection to invoke a private method?