Custom OrderBy on a List

前端 未结 5 1157
旧巷少年郎
旧巷少年郎 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条回答
  •  闹比i
    闹比i (楼主)
    2021-02-18 19:31

    query = query.OrderBy(x =>
      x.Status == "Urgent" ? 1:
      x.Status == "Normal" ? 2:
      3)
      .ThenBy(x => 
      x.Status == "Urgent" ? null:
      x.Status == "Normal" ? x.Date:
      null);
    

    Random musing: Does Ordering belong to the query, or to the class?

提交回复
热议问题