Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display Text for Enum [duplicate]

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

like image 485
Tassadaque Avatar asked Nov 28 '22 09:11

Tassadaque


2 Answers

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?

like image 188
Upendra Chaudhari Avatar answered Dec 20 '22 02:12

Upendra Chaudhari


How about using a valid identifier like B_Plus?

like image 34
Gary Avatar answered Dec 20 '22 04:12

Gary