创建一个控制台应用程序,定义枚举类型monthtype表示十二个月,输入1-12中的某一个数,输出对应月份的英文缩写。如:
输入 6输出  jun注:十二月份的英文缩写分别为:jan,feb,mar,apr,may,jun ,jul,aug,sep,oct,nov,dec ...求范文

解决方案 »

  1.   

    class Program
        {
            public enum Month
            {
                jan = 1, 
                feb = 2,
                mar = 3, 
                apr = 4,
                may = 5,
                jun = 6, 
                jul = 7, 
                aug = 8,
                sep = 8,
                oct = 10, 
                nov = 11,
                dec = 10
            }        static void Main(string[] args)
            {
                Console.WriteLine("请输入月份");
                string str = Console.ReadLine();
                Console.WriteLine(Convert.ToInt32((Month)Enum.Parse(typeof(Month), str)));            Console.ReadLine();           
            }
      

  2.   

     public enum Month
            {
                jan = 1, 
                feb = 2,
                mar = 3, 
                apr = 4,
                may = 5,
                jun = 6, 
                jul = 7, 
                aug = 8,
                sep = 8,
                oct = 10, 
                nov = 11,
                dec = 10
            }
    写在class的外面。
      

  3.   

    string month= Console.ReadLine();
     Month eMonth=  (Month)Enum.Parse(typeof(Month), month);
    Console.WriteLine(eMonth.ToString());