排序列表<&日期时间GT;降序 [英] Sort List<DateTime> Descending

查看:120
本文介绍了排序列表<&日期时间GT;降序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#(3.0或3.5,所以我们可以使用lambda表达式),有排序按降序排列日期列表的一个优雅的方式?我知道我可以做直排序,然后扭转整个事情,

In c# (3.0 or 3.5, so we can use lambdas), is there an elegant way of sorting a list of dates in descending order? I know I can do a straight sort and then reverse the whole thing,

docs.Sort((x, y) => x.StoredDate.CompareTo(y.StoredDate));
docs.Reverse();



但有一个lambda表达式做一步?

but is there a lambda expression to do it one step?

在上面的例子中,StoredDate是类型为DateTime的属性。

In the above example, StoredDate is a property typed as a DateTime.

推荐答案

虽然它是未经测试..

Though it's untested...

docs.Sort((x, y) => y.StoredDate.CompareTo(x.StoredDate));



应该是你原本的正好相反。

should be the opposite of what you originally had.

这篇关于排序列表<&日期时间GT;降序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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