欢迎来到萧静默的博客

书山有路勤为径,学海无涯苦作舟。

C#简单的枚举及结构

using System;
namespace program
{
    enum WeekDays
    {
        a,//0
        b,//1
        c = 11,//11 赋值以后就变成11,不赋值就是2
        d,//12
        e,//13
        f,//14
        g//15
    }//不能输入数字


    struct student {
        public string name;
        public char sex;
        public int age;
    }
    class program1
    {
        static void Main(string[] args)
        {
            WeekDays letter;
            letter = WeekDays.e;
            for (letter = 0; letter < WeekDays.g; letter++)
            {
                Console.WriteLine(letter);//看看枚举里的值到底是多少
            }

            student Bruce;//结构体的运用
            Bruce.age = 18;
            Bruce.name = "布鲁斯";
            Bruce.sex = '';
            student Talyo;
            Talyo.age = 19;
            Talyo.name = "泰勒";
            Talyo.sex = '';
            Console.WriteLine("姓名:{0}",Bruce.name);
            Console.WriteLine("年龄:{0}",Bruce.age);
            Console.WriteLine("性别:{0}",Bruce.sex);
            Console.WriteLine("姓名:{0}",Talyo.name);
            Console.WriteLine("年龄:{0}", Talyo.age);
            Console.WriteLine("性别:{0}", Talyo.sex);
        }
    }
}

 

posted @ 2019-11-06 14:42  萧静默  阅读(460)  评论(0编辑  收藏  举报