结构的使用

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

namespace ConsoleApp1
{
    

    public enum Gender
    {
        男,
        女
    }

    public struct Person//此处定义结构
    {
        public string name;//注意,这里的常量如果不定义为公有,则主方法中无法直接赋值
        public int age;
        public Gender gender;//注意这里的性别类型来自枚举

    }



    class Program
    {
        static void Main(string[] args)
        {
            Person zsPerson;
            zsPerson.name = "张三";
            zsPerson.age = 16;
            zsPerson.gender = Gender.男;
            

            Console.WriteLine(zsPerson.name);
            Console.WriteLine(zsPerson.age);
            Console.WriteLine(zsPerson.gender);
            Console.ReadKey();







        }
    }
}

  

原文地址:https://www.cnblogs.com/ssC2H4/p/8735472.html