实现效果:
实现代码:
static void Main(string[] args) { Console.WriteLine("***A First Look at Structures*** "); //创建初始Point Point myPoint = new Point(); //使用默认构造函数将所有字段设置为默认值 myPoint.x = 199; myPoint.y = 99; myPoint.Display(); //调整X和Y myPoint.Increment(); myPoint.Display(); Console.ReadKey(); } struct Point { //结构的字段 public int x; public int y; //将XY坐标增加1 public void Increment() { x++; y++; } //将XY坐标减去1 public void Decrement() { x--; y--; } //显示当前坐标 public void Display() { Console.WriteLine("X={0},Y={1}",x,y); } }