从字符串数组中排序日期

Sup*_*Sup 2 c# arrays string date

如果我有一个字符串数组中的日期,例如23/05/2011,17/03/2012,01/07/2010等,是否可以先对年份进行排序,然后对几天进行排序,而不是先排序日期?

Tim*_*ter 6

你可以先解析它们DateTime:

var orderedByDateTime = strings
    .Select(s => new { s, dt = DateTime.ParseExact(s, "dd'/'MM'/'yyyy", null) })
    .OrderBy(x => x.dt)
    .Select(x => x.s);
Run Code Online (Sandbox Code Playgroud)