Sort List Descending

后端 未结 4 1789
无人共我
无人共我 2020-12-13 17:19

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

4条回答
  •  孤街浪徒
    2020-12-13 17:47

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

    Note the minus sign.

提交回复
热议问题