Custom OrderBy on a List

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

    You will need to provide an implementation of IComparer, and then you can pass it in using the following overload:

    public static IOrderedEnumerable OrderBy(
        this IEnumerable source,
        Func keySelector,
        IComparer comparer
    )
    

    See: http://msdn.microsoft.com/en-us/library/bb549422.aspx

提交回复
热议问题