Оператор += не может применяться к операндам типа - C#
Формулировка задачи:
Здравствуйте. Подскажите пожалуйста,почему получаю ошибку: Оператор += не может применяться к операндам типа Form1.Date и int
private void button1_Click(object sender, EventArgs e)
{
String s1;
s1 = textBox1.Text;
Double day1 = Double.Parse(s1);
String s2;
s2 = textBox2.Text;
Double month1 = Double.Parse(s2);
String s3;
s3 = textBox3.Text;
Double year1 = Double.Parse(s3);
Date A = new Date(day1, month1, year1);
Date B = new Date(A);
A.CheckData();
A+=3; //ОШИБКА ЗДЕСЬ
}
public class Date
{
public double day;
public double month;
public double year;
public Date(double d, double m, double y)//конструтор ініціалізації
{
day = d;
month = m;
year = y;
}
...
public void Date operator +(int k)
{
}
}Решение задачи: «Оператор += не может применяться к операндам типа»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OverLoad
{
class Point
{
public int x;
public int y;
public Point(int x, int y)
{
this.x = x;
this.y = y;
}
public static bool operator ==(Point p, Point other)
{
return p.x == other.x;
}
public static bool operator !=(Point p, Point other)
{
return p.x != other.x;
}
public override bool Equals(object obj)
{
Point p = (Point)obj;
return p.x == this.x;
}
public override int GetHashCode()
{
return x;
}
}
}