Sort string list with dates in C#

前端 未结 6 1618
不知归路
不知归路 2020-12-31 07:00

I have a List with dates.
My list is:

{\"01/01/2013\",\"10/01/2013\",\"20/01/2013\"}

I want to sort the list

6条回答
  •  难免孤独
    2020-12-31 08:02

    Because they are the UK/AUS format (Day/Month/Year), you can sort them using OrderByDescending:

    List dates = new List() { "01/01/2013", "10/01/2013", "20/10/2013" };
    
    foreach (var date in dates.OrderByDescending(x => x))
        Console.WriteLine(date);
    

    Personally I would convert them to DateTime objects first..

提交回复
热议问题