Enum value as hidden in C#

后端 未结 9 891
暖寄归人
暖寄归人 2020-12-21 01:40

I have an enum and i want to \"hide\" one of its values (as i add it for future support). The code is written in C#.

public enum MyEnum
{
   ValueA = 0,

            


        
9条回答
  •  别那么骄傲
    2020-12-21 02:38

    You could use the 'Obsolete' attribute - semantically incorrect, but it will do what you want:

    public enum MyEnum 
    { 
      ValueA = 0, 
      ValueB = 1, 
      [Obsolete("Do not use this", true)]
      Reserved 
    }
    

    Anyone who tries to compile using the Foo.Reserved item will get an error

提交回复
热议问题