Study Notes (49): C # fast entry - type structure

Learning immediately: https://edu.csdn.net/course/play/20589/257759?utm_source=blogtoedu

Physical structure of a plurality of different types of disposable declare variables

1. Syntax:

struct 结构名
{
    结构成员;
}

2. Example: Company Information Management

struct Person        //用struct关键字定义一个结构体,用于描述员工信息
    {
        public string name;                //姓名
        public Gender gender;        //性别,此处使用已经定义好的枚举类型
        public int age;                //年龄
        public string addr;            //住址

    }
    enum Gender                //枚举类型,性别
    {
        Male,
        Female
    }
    class Program
    {        
        static void Main(string[] args)
        {
            //声明结构体,并且赋值
            Person p1;
            p1.name = "张三";
            p1.gender = Gender.Male;
            p1.age = 18;
            p1.addr = "北京";

            Person p2;
            p2.name = "李四";
            p2.gender = Gender.Female;
            p2.age = 20;
            p2.addr = "河南";

            //使用结构体的值
            Console.WriteLine(p1.name+"的年龄是:"+p1.age+",性别是"+p1.gender);
            Console.ReadKey();
        }
    }

 

 

Published 34 original articles · won praise 0 · Views 299

Guess you like

Origin blog.csdn.net/u013162262/article/details/104885195
Recommended