结构

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 结构
{
    class Program
    {
        static void Main(string[] args)
        {
        }
    }
    //结构的级别跟类的级别一样,结构式值类型
    //能定义,方法,属性,字段,构造函数,也可以用new关键字来创建对象
   //1、结构中的字段不能赋初始值
    //2、无参数构造函数无论如何C#都自动生成,无法为结构定义一个无参数的构造函数
    //3、在构造函数中必须给函数的所有字段赋值
    //4、在 构造函数中为属性赋值,不认为是对字段赋值,因为属性不一定是去操作字段
    //5、不能定义自动属性,因为自动属性会生成1个字段,而这个字段必须要求在构造函数中给它赋值,但是我们不知道这个变量的名称,所以我发给它赋值
    struct Point
    {
        private int x;

        public int X
        {
            get { return x; }
            set { x = value; }
        }
        private int y;

        public int Y
        {
            get { return y; }
            set { y = value; }
        }

        public void Show()
        {
            Console.Write("hello world");
        }
        public Point(int x,int y)
        {
            this.x = x;
            this .y = y;
        }

    }
}
原文地址:https://www.cnblogs.com/sumg/p/3801006.html