SELECT * FROM [TFunds]
The ORDER BY CASE WHEN FilingDeadline & gt;=GetDate (), 1 END, THEN 0 ELSE IsRecommend Desc, ABS (DATEDIFF (hh, GetDate (), FilingDeadline)), PublishTime Desc
CodePudding user response:
Linq can such
The static void Main (string [] args)
{
ListList=new List () {
New TList () {Id=2, Name="a1", AddTime=DateTime. Now},
New TList () {Id=1, Name="a2", AddTime=DateTime. Now the AddDays (1)},
New TList () {Id=3, Name="a3", AddTime=DateTime. Now the AddDays (2)},
New TList () {Id=5, Name="a4", AddTime=DateTime. Now the AddDays (3)},
New TList () {Id=4, Name="a5", AddTime=DateTime. Now the AddDays (4)},
New TList () {Id=6, Name="a6", AddTime=DateTime. Now the AddDays (5)},
New TList () {Id=7, Name="a7", AddTime=DateTime. Now the AddDays (6)},
};
List_list=list. OrderBy (x=& gt; X.I d & gt; 4? 0:1). ThenByDescending (x=& gt; X.A ddTime). ThenByDescending (x=& gt; Math. Abs ((DateTime. Now. Subtract (x.A ddTime). TotalHours))). ToList ();
}
Public class TList
{
Public int Id {get; set; }
Public string Name {get; set; }
Public DateTime AddTime {get; set; }
}
CodePudding user response:
Orderbydescending (x=& gt; FilingDeadline & gt;=a DateTime. Now? 0:1). Thenbydescending (x=& gt; X.I sRecommend). Thenby (x=& gt; Abs (FilingDeadline Hour - a DateTime. Now. The adrenaline-charged)) thenbydescending (x=& gt; X.P ublishTime)