public static void Main(string [] args) { var t1 = new Time2(); // 00:00:00 var t2 = new Time2(2); // 02:00:00 var t3 = new Time2(21, 34); // 21:34:00 var t4 = new Time2(12, 25, 42); // 12:25:42 var t5 = new Time2(t4); // 12:25:42 Console.WriteLine(); Console.WriteLine(" Constructed with: \n "); Console.WriteLine(" t1: All arguments defaulted"); Console.WriteLine($" {t1.ToUniversalString()}"); // 00:00:00 Console.WriteLine($" {t1.ToString()}\n"); // 12:00:00 AM Console.WriteLine(" t2: Hour specified; minute and second defaulted"); Console.WriteLine($" {t2.ToUniversalString()}"); // 02:00:00 Console.WriteLine($" {t2.ToString()}\n"); // 2:00:00 AM Console.WriteLine(" t3: Hour and minute specified; second defaulted:"); Console.WriteLine($" {t3.ToUniversalString()}"); // 21:34:00 Console.WriteLine($" {t3.ToString()}\n"); // 9:34:00 PM Console.WriteLine(" t4: Hour, minute and second specified:"); Console.WriteLine($" {t4.ToUniversalString()}"); // 12:25:42 Console.WriteLine($" {t4.ToString()}\n"); // 12:25:42 PM Console.WriteLine(" t5: Time2 object t4 specified:"); Console.WriteLine($" {t5.ToUniversalString()}"); // 12:25:42 Console.WriteLine($" {t5.ToString()}\n"); // 12:25:42 PM // attempt to initialize t6 with invalid values try { var t6 = new Time2(27, 74, 99); // invalid time inputs } catch (ArgumentOutOfRangeException ex) { Console.WriteLine(" \nException while initializing t6: "); Console.WriteLine(ex.Message); Console.WriteLine(); } } // end Main Method
//Time2 Constructor with another Time2 object supplied as an argument public Time2(Time2 time) : this(time.Hour, time.minute, time.Second) { }