我有一个包含日期的列表:
List<string> StringDates;
[0]: "04.03.2010"
[1]: "09.03.2010"
[2]: "11.03.2010"
[3]: "12.03.2010"
[4]: "16.03.2010"
[5]: "18.03.2010"
[6]: "19.03.2010"
[7]: "23.03.2010"
[8]: "25.03.2010"
[9]: "26.03.2010"
使用 C# 从这个列表中找出最小日期/最大日期的最佳/最短方法是什么?
最佳答案
我喜欢简单的解决方案。
DateTime minDate = DateTime.MaxValue;
DateTime maxDate = DateTime.MinValue;
foreach (string dateString in StringDates)
{
DateTime date = DateTime.Parse(dateString);
if (date < minDate)
minDate = date;
if (date > maxDate)
maxDate = date;
}
关于asp.net - C# - 从列表中计算最小日期/最大日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2337770/