您的位置:首页 > 其它

enum 枚举 重要程度高于 结构体---初学者的记录

2016-04-21 18:49 246 查看
1,值类型;2,用法static void Main(string[] args)        {            student stu1=new  student();            stu1.name = "zhangsan";            stu1.sex = sex.男;//注意这里!!!!!!!!!!!!!!!!!!            stu1.age = 16;        }        struct student        {            public string name;            public sex sex;            public int age;                }        enum sex///////////////////enum:byte也行        { 男,//默认0            女//默认1}3,将枚举类型转换成string类型  (sex.男.Tostring)      将string类型转换成枚举类型  sex s=(sex)Enum.Parse(typeof(sex),"男");貌似用处不大。。。。。。也可以用强制类型转换4,注意foreach 语句后面没有;5  static void Main(string[] args)        {            food f = food.包子|food.饺子;。。。。。。。。。。。。。。用法            Console.WriteLine(f);                    }                     [Flags]         enum food         {包子=1,!!!!........................................重要  1 2 4 8 16 。。。。        饺子=2,!!!!            面条=4        }位枚举  [Flag]   enum i {       }6待更新。。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: