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(); }
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的外面。
{
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();
}
{
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的外面。
Month eMonth= (Month)Enum.Parse(typeof(Month), month);
Console.WriteLine(eMonth.ToString());