using System;
public struct Point
{
public double x;
public double y;
public Point(double x, double y)
{
this.x = x;
this.y = y;
}
// 运算符的重载,使加号具有新的功能
// 可以实现两个Point对象直接相加,得到一个新的点
public static Point operator +(Point p1, Point p2)
{
return new Point(p1.x + p2.x, p1.y + p2.y);
}
}
public class Program
{
public static void Main(string[] args)
{
Point p1 = new Point(1, 2);
Point p2 = new Point(2, 3);
Point p3 = p1 + p2;
Console.WriteLine(p3.x);
Console.WriteLine(p3.y);
}
}