Singular or plural for enumerations?

后端 未结 7 1673
长发绾君心
长发绾君心 2021-01-31 12:56

Do you use singular or plural for enumerations? I think it makes best sense with plural in the declaration

enum Weekdays
{
    Monday,
    Tuesday,
    Wednesday         


        
7条回答
  •  星月不相逢
    2021-01-31 13:47

    One recommendation comes from the .NET Framework Design Guidelines, page 59-60:

    Do use a singular type name for an enumeration, unless its values are bit fields.

    public enum ConsoleColor {
      Black,
      Blue,
      Cyan,
      ...
    

    Do use a plural type name for an enumeration with bit fields as values, also called a flags enum.

    [Flags]
    public enum ConsoleModifiers {
      Alt,
      Control,
      Shift
    }
    

提交回复
热议问题