Custom OrderBy on a List

前端 未结 5 1183
旧巷少年郎
旧巷少年郎 2021-02-18 18:51

I\'m trying to figure out the best way to custom sort a List. Lets say that T is a Object with a date(DateTime?) property and a status(string) property.

I have 3 cases.

5条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-18 19:18

    You could just use an extension method:

    Something like this...

    public static IOrderedEmumerable OrderForDisplay (this IEnumerable input)
    {
      return
        input
        .OrderBy(item => item.Status)
        .ThenByDescending(item => item.Status == 1 ? DateTime.MaxDate : item.date);
    }
    

提交回复
热议问题