LINQ orderby on date field in descending order

前端 未结 4 515
广开言路
广开言路 2020-12-24 06:18

How can I change the LINQ query in the code below to sort by date in descending order (latest first, earliest last)?

using System;
using System.Linq;
using S         


        
4条回答
  •  没有蜡笔的小新
    2020-12-24 06:36

    I was trying to also sort by a DateTime field descending and this seems to do the trick:

    var ud = (from d in env 
         orderby -d.ReportDate.Ticks                 
         select  d.ReportDate.ToString("yyyy-MMM") ).Distinct(); 
    

提交回复
热议问题