C#基础-050 结构

来源:互联网 发布:c语言if语句例题 编辑:程序博客网 时间:2024/06/06 00:11
 struct PointStruct    {        public int x;        public int y;        //结构不能显示的包含无参构造        //public PointStruct()        //{        //}        //在结构中显示的写出有参构造  不显示的写出无参构造  无参构造可以正常使用        public PointStruct(int x, int y)        {            this.x = x;            this.y = y;        }        public void Test()        {            Console.WriteLine("***********");        }    }
  static void Main(string[] args)        {            //PointStruct ps = new PointStruct();            //ps.x = 100;            //ps.y = 200;            //PointStruct ps1 = ps;            //ps1.x = 200;            //ps1.y = 300;            //Console.WriteLine(ps.x +"  " + ps.y);            //Console.WriteLine(ps1.x+"   "+ ps1.y);            PointStruct[] psArr = new PointStruct[10];//创建了1个对象            for (int i = 0; i < psArr.Length; i++)            {                psArr[i].x = i;                psArr[i].y = i;            }            PointClass[] pcArr = new PointClass[10];//创建了1个对象            for (int i = 0; i < pcArr.Length; i++)            {                pcArr[i] = new PointClass(100+i,200+i);            }        }
原创粉丝点击