在C#日期排序字符串列表 [英] Sort string list with dates in C#
本文介绍了在C#日期排序字符串列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个列表<串>
使用日期结果
我的列表是:
I have a List<string>
with dates.
My list is:
{"01/01/2013","10/01/2013","20/01/2013"}
我要排序的名单看起来是这样的:
I want to sort the list to look like this:
{"20/01/2013","10/01/2013","01/01/2013"}
我怎样才能让这个
推荐答案
使用LINQ:
var list = new List<string> {"01/01/2013", "10/01/2013", "20/01/2013"};
var orderedList = list.OrderByDescending(x => DateTime.Parse(x)).ToList();
这篇关于在C#日期排序字符串列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文