Enumerations

  • DO use PascalCasing.

  • DO use a singular type name for an enumeration unless its values are bit fields.

    public enum Severity
    {
        Mild,
        Medium,
        Serious,
        Nuclear
    }
    
  • DO use a plural type name for an enumeration with bit fields as values, also called flags enum:

    [Flags]
    enum Visibilities {
        Private = 1,
        Internal = 2,
        Public = 4
    }
    

    Why: Plural flags because enum can hold multiple values (using bitwise ‘OR’).

  • DO NOT use an “Enum” suffix in enum type names.

    // Avoid
    public enum CoinEnum
    {
        Penny,
        Nickel,
        Dime,
        Quarter,
        Dollar
    }
    
    // Correct
    public enum Coin
    {
        Penny,
        Nickel,
        Dime,
        Quarter,
        Dollar
    }
    
  • DO NOT use “Flag” or “Flags” suffixes in enum type names.

    // Avoid
    [Flags]
    public enum DockingsFlags
    {
      None = 0,
      Top = 1,
      Right = 2,
      Bottom = 4,
      Left = 8
    }
    
    // Correct
    [Flags]
    public enum Dockings
    {
      None = 0,
      Top = 1,
      Right = 2,
      Bottom = 4,
      Left = 8
    }
    
  • DO NOT use a prefix on enumeration value names (e.g., “ad” for ADO enums, “rtf” for rich text enums, etc.).

    // Avoid
    enum Visibility
    {
        visPublic,
        visInternal,
        visPublic
    }
    
  • DO NOT explicitly specify a type of an enum or values of enums (except bit fields)

    // Avoid
    public enum Direction : long
    {
        North = 1,
        East = 2,
        South = 3,
        West = 4
    }
    
    // Correct
    public enum Direction
    {
        North,
        East,
        South,
        West
    }
    

    Why: can create confusion when relying on actual types and values.

Learn More