using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleSuanFa
{
public class Point
{
private int x;
private int y;
public int X
{
get { return this.x; }
set { this.x = value; }
}
public int Y
{
get { return this.y; }
set { this.y = value; }
}
public Point(int x, int y)
{
this.x = x;
this.y = y;
}
public static Point operator +(Point p1, Point p2)
{
return new Point(p1.x + p2.x, p1.y + p2.y);
}
public Point()
{}
public void toString()
{
Console.Write("the x is "+ this.X+"and the y is"+ this.Y);
}
}
class OperatorOverload
{
public static void Main(string[] args)
{
Point p1 = new Point();
p1.X = 5;
p1.Y = 5;
Point p2 = new Point(5, 5);
Point p3 = p1 + p2;
p3.toString();
}
}
}
正文完