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