asp.net - C# - 从列表中计算最小日期/最大日期

标签 asp.net date find max min

我有一个包含日期的列表:

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/

相关文章:

c# - 列表框 SelectedIndex 始终返回 -1

date - 使 sybase 中的列默认为行插入的当前日期/时间

linux - 如何查找在过去 24 小时内修改过的文件,但不从隐藏目录中找到文件并对它们求和

javascript - MongoDB 查找具有多个 eq 的 expr

sql - Datepart 和 @@datefirst 的区别

eclipse - Eclipse IDE 中是否存在 "Find in project..."功能?

asp.net - 为什么 IIS 线程与常规 CLR 线程相比如此宝贵?

c# - 阻止页面生命周期?

jquery - 如何解决错误: $ is not defined in jquery?

Play Framework 的日期和时间?