Friday, December 6, 2013

Sort DateTime List c#

    
    var sortedDates = dates.OrderByDescending(x => x);

or else Don't want to use, or don't know Linq then you can go for following..

    static List SortAscending(List list)
    {
    list.Sort((a, b) => a.CompareTo(b));
    return list;
    }

    static List SortDescending(List list)
    {
    list.Sort((a, b) => b.CompareTo(a));
    return list;
    }

No comments:

Post a Comment