OrderBy descending in Lambda expression?
我知道在正常的Linq语法中, orderby xxx descending
很容易,但我如何在Lambda表达式中执行此操作?
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);
Use System.Linq.Enumerable.OrderByDescending()
?
For example:
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/90344.html
上一篇: 用包含在该lambda中的匿名类型定义lambda表达式
下一篇: OrderBy以Lambda表达式降序?