本文整理匯總了C#中System.DateTime.MaxValue字段的典型用法代碼示例。如果您正苦於以下問題:C# DateTime.MaxValue字段的具體用法?C# DateTime.MaxValue怎麽用?C# DateTime.MaxValue使用的例子?那麽, 這裏精選的字段代碼示例或許可以為您提供幫助。您也可以進一步了解該字段所在類System.DateTime
的用法示例。
在下文中一共展示了DateTime.MaxValue字段的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: if
// Attempt to assign an out-of-range value to a DateTime constructor.
long numberOfTicks = Int64.MaxValue;
DateTime validDate;
// Validate the value.
if (numberOfTicks >= DateTime.MinValue.Ticks &&
numberOfTicks <= DateTime.MaxValue.Ticks)
validDate = new DateTime(numberOfTicks);
else if (numberOfTicks < DateTime.MinValue.Ticks)
Console.WriteLine("{0:N0} is less than {1:N0} ticks.",
numberOfTicks,
DateTime.MinValue.Ticks);
else
Console.WriteLine("{0:N0} is greater than {1:N0} ticks.",
numberOfTicks,
DateTime.MaxValue.Ticks);
輸出:
9,223,372,036,854,775,807 is greater than 3,155,378,975,999,999,999 ticks.
示例2: Main
//引入命名空間
using System;
using System.Globalization;
class MainClass {
public static void Main() {
Console.WriteLine("Min Date: {0}", DateTime.MinValue.ToString());
Console.WriteLine("Max Date: {0}", DateTime.MaxValue.ToString());
}
}