分 享

【凤凰社】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);
        }
    }
}

 


0 评论

回复