按日期降序显示值

时间:2016-05-31 04:53:02

标签: c# sorting lambda

我有c#返回2个日期的数据列表。

5/31/2016 4:34:41 AM
5/31/2016 4:38:08 AM

我正在使用lambda表达式对它们进行排序以显示最新日期。但它仍显示错误。可能是什么问题。

var rowEntities = 
    MyOperations.GetEntitiesByDate().ToList().OrderByDescending(i=>i.JobStartTime);

public DateTime JobStartTime { get; set; }

2 个答案:

答案 0 :(得分:1)

var rowEntities = MyOperations.GetEntitiesByDate().ToList().OrderByDescending(i=>i.JobStartTime);

var rowEntities = (from dates in MyOperations.GetEntitiesByDate() orderby dates.jobstarttime select dates).Tolist();

var rowEntities = (from dates in MyOperations.GetEntitiesByDate() orderby dates.jobstarttime ascending or descending select dates).Tolist();

答案 1 :(得分:1)

尝试

var rowEntities = MyOperations.GetEntitiesByDate().OrderByDescending(i=>i.JobStartTime).ToList();