//To reuse the code public TheDate(TheDate d) : this(d.day, d.month, d.year, d.separator) { /* TODO: create a copy of object ‘d’. This type of constructor is normally called “copy constructor”. Hint: use d.day, d.month */ //this.day = d.day; //this.month = d.month; //this.year = d.year; //this.separator = d.separator; }
static void Main(string[] args) { TheDate d1 = new TheDate(); d1.SetDay(4); d1.SetMonth(9); d1.SetYear(2015); d1.SetSaparator('~'); TheDate d2 = new TheDate(4, 9, 2015, '-'); TheDate d3 = new TheDate(d1); d3.SetSaparator('/'); Console.WriteLine(d1.ToString()); Console.WriteLine(d2.ToString()); Console.WriteLine(d3.ToString()); Console.ReadKey(); }
public int Compare(TheDate d) { int result = 0; /*TODO: Return 0 if dates are equal Return -1 if Object d is less. Return 1 if Object d is greater. */ if (d.year > this.year) result = 1; else if (d.year < this.year) result = -1; else { if (d.month > this.month) result = 1; else if (d.month < this.month) result = -1; else { if (d.day > this.day) result = 1; else if (d.day < this.day) result = -1; else result = 0; } } return result; }