我知道在普通的 Linq 语法中,orderby xxx descending很容易,但是我如何在 Lambda 表达式中做到这一点?
orderby xxx descending
正如布兰农所说,它是OrderByDescendingand ThenByDescending:
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);