Enum “Inheritance”

后端 未结 15 1482
野性不改
野性不改 2020-11-22 07:21

I have an enum in a low level namespace. I\'d like to provide a class or enum in a mid level namespace that \"inherits\" the low level enum.

namespace low
{
         


        
15条回答
  •  情歌与酒
    2020-11-22 08:09

    This is not possible. Enums cannot inherit from other enums. In fact all enums must actually inherit from System.Enum. C# allows syntax to change the underlying representation of the enum values which looks like inheritance, but in actuality they still inherit from System.enum.

    See section 8.5.2 of the CLI spec for the full details. Relevant information from the spec

    • All enums must derive from System.Enum
    • Because of the above, all enums are value types and hence sealed

提交回复
热议问题