枚举类型跟各种类型之间转换

枚举类型和各种类型之间转换
 //声明枚举
            public enum Sesons
            {
                春,
                夏,
                秋,
                冬
            }
 static void Main(string[] args)
            {
                Sesons s = Sesons.春;
               
                string str="0";
                //枚举类型可以直接转换成int类型int s=(int)Sesons.春
int cun=(int)Sesons.春;;
//结果等于cun=0
               

枚举类型转字符串string类型

    //声明枚举
            public enum Sesons
            {
                春,
                夏,
                秋,
                冬
            }
            //声明枚举
            public enum QQstate
            {
                OnLine,
                OffLine,
                leave,
                QMe
            }
            static void Main(string[] args)
            {
                Sesons s = Sesons.春;
              
                QQstate q = QQstate.OnLine;
                string str="0";
                //枚举类型可以直接转换成int类型int s=(int)QQstate.春
                //将字符串转换成枚举Enum.Parse,typeof(),获取对象类型
                QQstate qzx=(QQstate)Enum.Parse(typeof(QQstate),str);
                Console.WriteLine(qzx);
                Console.ReadKey();
            }