OrderBy以Lambda表达式降序?
我知道在正常的Linq语法中, orderby xxx descending
很容易,但我如何在Lambda表达式中执行此操作?
正如Brannon所说,它是OrderByDescending
和ThenByDescending
:
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