通过按Lambda表达式降序? [英] OrderBy descending in Lambda expression?

查看:649
本文介绍了通过按Lambda表达式降序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在通常的Linq语法中,orderby xxx descending非常简单,但是如何在Lambda表达式中做到这一点?

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

推荐答案

正如布兰农所说,它是 ThenByDescending :

As Brannon says, it's OrderByDescending and 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);

这篇关于通过按Lambda表达式降序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆