How to set space on Enum

后端 未结 14 1389
栀梦
栀梦 2020-11-29 08:00

I want to set the space on my enum. Here is my code sample:

public enum category
{
    goodBoy=1,
    BadBoy
}

I want to set



        
相关标签:
14条回答
  • 2020-11-29 08:45
    public enum MyEnum { With_Space, With_Two_Spaces } //I store spaces as underscore. Actual values are 'With Space' and 'With Two Spaces'
    
    public MyEnum[] arrayEnum = (MyEnum[])Enum.GetValues(typeof(MyEnum));
    
    string firstEnumValue = String.Concat(arrayEnum[0].ToString().Replace('_', ' ')) //I get 'With Space' as first value
    string SecondEnumValue = String.Concat(arrayEnum[1].ToString().Replace('_', ' ')) //I get 'With Two Spaces' as second value
    
    0 讨论(0)
  • 2020-11-29 08:47

    An enumerator cannot contain white space in its name.

    As we know that enum is keyword used to declare enumeration.

    you can check throw this link https://msdn.microsoft.com/en-us/library/sbbt4032.aspx

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