ITPub博客

首页 > 应用开发 > > 枚举可以在方法中声明吗

枚举可以在方法中声明吗

作者:dapan 时间:2019-08-12 14:12:48 0 删除 编辑

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/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2020-08-07

  • 博文量
    4504
  • 访问量
    87280