- using System;
-
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- // 比較元の日付の方が過去の場合
- Console.WriteLine("new DateTime(2013, 3, 31).CompareTo(new DateTime(2013, 4, 1)) → " + new DateTime(2013, 3, 31).CompareTo(new DateTime(2013, 4, 1)));
- // 同じ日付の場合
- Console.WriteLine("new DateTime(2013, 4, 1).CompareTo(new DateTime(2013, 4, 1)) → " + new DateTime(2013, 4, 1).CompareTo(new DateTime(2013, 4, 1)));
- // 比較もとの日付の方が未来の場合
- Console.WriteLine("new DateTime(2013, 4, 2).CompareTo(new DateTime(2013, 4, 1)) → " + new DateTime(2013, 4, 2).CompareTo(new DateTime(2013, 4, 1)));
-
-
- /* 比較演算子でも比較可能 */
-
- // 比較元の日付の方が過去の場合
- Console.WriteLine("new DateTime(2013, 3, 31) < new DateTime(2013, 4, 1) → " + (new DateTime(2013, 3, 31) < new DateTime(2013, 4, 1)));
- Console.WriteLine("new DateTime(2013, 3, 31) > new DateTime(2013, 4, 1) → " + (new DateTime(2013, 3, 31) > new DateTime(2013, 4, 1)));
- Console.WriteLine("new DateTime(2013, 3, 31) == new DateTime(2013, 4, 1) → " + (new DateTime(2013, 3, 31) == new DateTime(2013, 4, 1)));
-
- // 同じ日付の場合
- Console.WriteLine("new DateTime(2013, 4, 1) < new DateTime(2013, 4, 1) → " + (new DateTime(2013, 4, 1) < new DateTime(2013, 4, 1)));
- Console.WriteLine("new DateTime(2013, 4, 1) > new DateTime(2013, 4, 1) → " + (new DateTime(2013, 4, 1) > new DateTime(2013, 4, 1)));
- Console.WriteLine("new DateTime(2013, 4, 1) == new DateTime(2013, 4, 1) → " + (new DateTime(2013, 4, 1) == new DateTime(2013, 4, 1)));
-
- // 比較もとの日付の方が未来の場合
- Console.WriteLine("new DateTime(2013, 4, 2) < new DateTime(2013, 4, 1) → " + (new DateTime(2013, 4, 2) < new DateTime(2013, 4, 1)));
- Console.WriteLine("new DateTime(2013, 4, 2) > new DateTime(2013, 4, 1) → " + (new DateTime(2013, 4, 2) > new DateTime(2013, 4, 1)));
- Console.WriteLine("new DateTime(2013, 4, 2) == new DateTime(2013, 4, 1) → " + (new DateTime(2013, 4, 2) == new DateTime(2013, 4, 1)));
-
- Console.ReadLine();
- }
- }
- }
|