Enums

  • AVOID converting enums to string.

    Calling Enum.ToString in .NET is very costly, as reflection is used internally for the conversion and calling a virtual method on struct causes boxing. As much as possible, this should be avoided.

    Oftentimes, enums can actually be replaced by const strings:

    // In both cases, you can use Numbers.One, Numbers.Two, ...
    public enum Numbers
    {
        One,
        Two,
        Three
    }
    
    public static class Numbers
    {
        public const string One = "One";
        public const string Two = "Two";
        public const string Three = "Three";
    }
    

    If you really need an enum, then consider using enumeration classes .

Learn More