Equivalent of Math.Min & Math.Max for Dates?

后端 未结 9 1924
渐次进展
渐次进展 2020-12-13 05:16

What\'s the quickest and easiest way to get the Min (or Max) value between two dates? Is there an equivalent to Math.Min (& Math.Max) for dates?

I want to do som

9条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-13 05:57

    How about a DateTime extension method?

    public static DateTime MaxOf(this DateTime instance, DateTime dateTime)
    {
        return instance > dateTime ? instance : dateTime;
    }
    

    Usage:

    var maxDate = date1.MaxOf(date2);
    

提交回复
热议问题