4

HI
I have the following enum

public enum Priority : byte 
    {
        A=1,
        B+ = 2,
        B=4,
        C=8,
        D=16,
        E=32
    }

I want to add B+ in the enum but it is giving me error

4

4 Answers 4

17

You can add user friendly description for enum like below :

enum MyEnum 
{ 
    [Description("This is black")] 
    Black, 
    [Description("This is white")] 
    White 
} 

Ref. Link : How to have userfriendly names for enumerations?

Sign up to request clarification or add additional context in comments.

Comments

5

How about using a valid identifier like B_Plus?

1 Comment

It is the business requirement to show B+ in drop down
2

Yes. It's giving you an error because your code is wrong. You can't make "B+" an enum value because there's a plus sign. Same reason you can't declare int B+. Use a different name.

Comments

0

You won't be able to use + as a name identifier because it's a math operator or string concatenator... it can't be used with enums. Use an alternative syntax, or use an alternative approach. You could consider a state design pattern:

http://www.dofactory.com/patterns/PatternState.aspx#_self2

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.