using System; public struct Point ... { /**//* * 功能 * struct不允许无参数的构造函数,如下: * * public Point(){} * * / /* * 功能 * 构造一个Point对象 * 参数 * x in X坐标 * y in Y坐标 */ public Point(int x,int y) ...{ this.x = x; this.y = y; } /**//* * 演示struct的成员函数功能 * 功能 * 设置点的坐标 * 参数 * x in X坐标 * y in Y坐标 */ public void SetPoint(int x,int y) ...{ this.x = x; this.y = y; } /**//* * 演示struct的成员函数功能 * 功能 * 获取当前点 * 参数 * 无 * 返回值 * 当前这个点对象,注意这个是对象复制 */ public Point GetPoint() ...{ Point pt; pt.x = x; pt.y = y; //这是对象复制操作 return pt; } /**//* * 演示struct的属性功能 * 创建一个X坐标的属性 */ public int X ...{ get ...{ return x; } set ...{ x = value; } } /**//* * 演示struct的属性功能 * 创建一个Y坐标的属性 */ public int Y ...{ get ...{ return y; } set ...{ y = value; } } //演示struct的成员变量功能,struct也不允许使用初始化变量对成员进行赋值,如下 //private int x = 0; //private int y = 0; private int x ; private int y ;} public class CallPoint ... { public static void test() ...{ //使用new来创建一个struct对象 Point pt = new Point(5,5); Console.WriteLine("({0},{1})", pt.X, pt.Y); pt.X = 10; pt.Y = 20; Console.WriteLine("({0},{1})", pt.X, pt.Y); //测试成员函数 pt.SetPoint(30, 30); //测试值传递 Console.WriteLine("({0},{1})", pt.GetPoint().X, pt.GetPoint().Y); }} ;