1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;
namespace DuoTai2 { class Program { static void Main(string[] args) { one test1 = new one(1,2); one test2 = new one(3, 4); Console.WriteLine((test1+test2).ToString()); Console.WriteLine((test2-test1).ToString()); Console.ReadKey();
} } public struct one { private int x; private int y; public one (int x,int y) { this.x = x; this.y = y; } public override string ToString() { return string.Format("坐标{0},{1}",x,y); } public static one operator+(one p1,one p2) { return new one(p1.x + p2.x, p1.y + p2.y); } public static one operator -(one p1, one p2) { return new one(p1.x - p2.x, p1.y - p2.y); } } }
|