首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C#枚举类型的运用,该如何处理

2012-04-09 
C#枚举类型的运用创建一个控制台应用程序,定义枚举类型monthtype表示十二个月,输入1-12中的某一个数,输出

C#枚举类型的运用
创建一个控制台应用程序,定义枚举类型monthtype表示十二个月,输入1-12中的某一个数,输出对应月份的英文缩写。如:
输入 6

输出 jun

注:十二月份的英文缩写分别为:jan,feb,mar,apr,may,jun ,jul,aug,sep,oct,nov,dec

 ...求范文

[解决办法]

C# code
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();                   } 

热点排行