enum Test
{A,B}
public class Program //when开发者_JAVA技巧 I remove public, it works
{
public Test a = Test.A;
static void Main(string[] args)
{
}
}
You haven't put an access modifier on your enum declaration, and then you are exposing it as a public field of your Program class. If you don't declare an access modifier, it is private.
public enum Test { A, B }
Because you have not explicitly declared an access modifier (ie. public, protected, internal) on your enum, it takes the default value (which is internal for classes and enums). You are then exposing that enum via a public field of your Program class, which is not allowed as the enum is not visible outside of its assembly.
You need to either declare the enum as public, or change the access modifier of the field to internal or private.
It works when you remove public from the Program class because it changes the Program class to be internal - the same as the enum. This is fine as neither of them are publicly exposed.
You can't make the property public because the enum is private. The public property would be externally public should someone use your program and the compiler tells you about it.
you probably need to set the enumeration to public
加载中,请稍侯......
精彩评论