Better Way To Get Char Enum

Just cast the value:

char status = (char)Enums.DivisionStatus.Active;

Note that this will use the value instead of the identifier. The Enums.DivisionStatus.Active value is the character code of 'A', as that is the value that you have defined.

Using the value directly is faster than looking up the identifier for the value.


You could also use a static class. Although, if you're always going to use the values as strings, you could just as easily make each property a string instead. One advantage of this method is that you can add descriptions for each item that will show up in the IntelliSense.

public static class DivisionStatus
{
    /// <summary>
    /// Some information about None
    /// </summary>
    public const char None = 'N';
    /// <summary>
    /// Some information about Active, blah blah
    /// </summary>
    public const char Active = 'A';
    /// <summary>
    /// Some information about Inactive, blah blah
    /// </summary>
    public const char Inactive = 'I';
    /// <summary>
    /// Some information about Waitlist, blah blah
    /// </summary>
    public const char Waitlist = 'W';
}

Tags:

C#

Enums

Char