枚举类型的声明

namespace c编程练习题
{ 
    public enum Seasons      //在域名区域声明枚举类型 Seasons.方便团队开发.
    {
        春,
        夏,
        秋,
        冬,
    }

    class Program
    {
        static void Main(string[] args)
        {
            Seasons s = Seasons.春;        //声明一个枚举类型s.
   public   enum gender
       { 
          男,
          女,
       }
  
        static void Main(string[] args)
       {
           gender s1 = gender.男;
           string s = "0";
           gender s2 = (gender)Enum.Parse(typeof(gender), s);
           Console.WriteLine(s1);
           Console.WriteLine(s2);

将string类型的变量转变成枚举类型的变量。【枚举名    新变量=(枚举名)Enum.Parse(typeof(枚举名),要转换的变量名);】

原文地址:https://www.cnblogs.com/kangshuai/p/4571205.html