Реализация оператора сложения для даты - C#
Формулировка задачи:
Помогите реализовать эти два оператора в мейне
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace qqq
{
class Program
{
static void Main(string[] args)
{
}
}
public class ClassDate
{
private int month;
private int year;
const int initMonth = 1;
const int initYear = 2013;
public ClassDate()
{
this.month = initMonth;
this.year = initYear;
}
public ClassDate(int month, int year)
{
this.month = month;
this.year = year;
}
public int GetMonth()
{
return month;
}
public int GetYear()
{
return year;
}
public static ClassDate operator +(ClassDate d1, ClassDate d2)
{
ClassDate result = new ClassDate();
result.month = (d1.month + d2.month) % 12;
result.year = d1.year + d2.year + (int)(d1.month + d2.month) / 12;
return result;
}
public static ClassDate operator +(ClassDate d1, int m)
{
ClassDate result = new ClassDate();
result.month = (d1.month + m) % 12;
result.year = d1.year + (int)(d1.month + m) / 12;
return result;
}
}
}Решение задачи: «Реализация оператора сложения для даты»
textual
Листинг программы
static void Main(string[] args)
{
ClassDate classDate1 = new ClassDate(12, 15);
ClassDate classDate2 = new ClassDate(10, 14);
ClassDate classDate3 = classDate1 + classDate2;
ClassDate classDate4 = classDate1 + 5;
}