主题:新手请教:为什么不能在方法中定义枚举?
刚开始学习C#,看到枚举这一段,写了个小程序试试,是这样的
using System;
class Welcome
{
public static void Main()
{
enum WeekDay
{
Sunday,Monday,Tuesday,Wednesday,Thursday,Saturday
};
Console.WriteLine("please enter your name");
x=Console.ReadLine();
Console.WriteLine(x);
}
}
用vs2005命令提示编译,提示错误信息。
如果放在方法外定义,就没有错误,如下:
using System;//表示导入名字空间,类似C语言中的#include
class Welcome
{
public static void Main()
{
Console.WriteLine("please enter your name");
x=Console.ReadLine();
Console.WriteLine(x);
}
enum WeekDay
{
Sunday,Monday,Tuesday,Wednesday,Thursday,Saturday
};
}
是枚举不能定义在方法内么?请假各位了,谢谢!!
using System;
class Welcome
{
public static void Main()
{
enum WeekDay
{
Sunday,Monday,Tuesday,Wednesday,Thursday,Saturday
};
Console.WriteLine("please enter your name");
x=Console.ReadLine();
Console.WriteLine(x);
}
}
用vs2005命令提示编译,提示错误信息。
如果放在方法外定义,就没有错误,如下:
using System;//表示导入名字空间,类似C语言中的#include
class Welcome
{
public static void Main()
{
Console.WriteLine("please enter your name");
x=Console.ReadLine();
Console.WriteLine(x);
}
enum WeekDay
{
Sunday,Monday,Tuesday,Wednesday,Thursday,Saturday
};
}
是枚举不能定义在方法内么?请假各位了,谢谢!!