首页 > 应用开发 > > 枚举可以在方法中声明吗
using System;
namespace ns{
classaa{staticvoidMain(string[] args){enumDay { Sun, Mon, Tue, Wed, Thu, Fri, Sat };//放在main方法中为什么不可以inty = (int)Day.Fri; Console.WriteLine(Day.Sun); Console.WriteLine("Fri = {0}", y);
}
}
}
报错:
c:\program\bb.cs(6,34): error CS1513: } expected
c:\program\bb.cs(9,26): error CS1519: Invalid token '(' in class, struct, or interface member declaration
c:\program\bb.cs(9,34): error CS1519: Invalid token ')' in class, struct, or interface member declaration
c:\program\bb.cs(10,26): error CS1519: Invalid token '(' in class, struct, or interface member declaration
c:\program\bb.cs(10,41): error CS1519: Invalid token ')' in class, struct, or interface member declaration
c:\program\bb.cs(15,1): error CS1022: Type or namespace definition, or end-of-file expected
枚举必须放在class aa里面吗?
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/758/viewspace-3153714/ ,如需转载,请注明出处,否则将追究法律责任。