C# what difference enum in namespace than enum inside a class

后端 未结 1 739
谎友^
谎友^ 2021-01-13 02:23

i have a question about enums that the codes are below:

namespace space
{
    public enum MyEnums
    {
        Enum1,Enum2,...
    }
}

namespace space
{
           


        
相关标签:
1条回答
  • 2021-01-13 02:56

    Well syntactically the only difference is that you'd preface the enum type with the containing class:

    MyClass.MyEnums.Enum1 
    

    versus just

    MyEnums.Enum1 
    

    (in both cases the namespace is assumed to be covered with a using directive)

    However, containing it within the class also lets you apply accessibility differently - you could have a private enum that is only usable within that class, while an enum within a namespace must be either public or internal.

    0 讨论(0)
提交回复
热议问题