Custom OrderBy on a List

前端 未结 5 1160
旧巷少年郎
旧巷少年郎 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:32

    The easiest way in my opinion is to use linq :

    itemsList = itemsList.OrderByDescending(ob => ob.status ).ThenBy(ob => ob.date).ToList();
    

提交回复
热议问题