枚举是单数还是复数?
枚举时使用单数还是复数?我认为在声明中使用复数是最有意义的
enum Weekdays
{
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday,
Sunday
}
......但我认为在使用类型时使用单数更有意义,例如
Weekday firstDayOfWeek = Weekday.Monday;
我在某处读到建议使用单数whith常规枚举和带有标志的复数,但我想听听更多的优点和缺点。
Do you use singular or plural for enumerations? I think it makes best sense with plural in the declaration
enum Weekdays
{
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday,
Sunday
}
... but I think it makes more sense with singular when using the type, e.g.
Weekday firstDayOfWeek = Weekday.Monday;
I read a recommendation somewhere to use singular whith regular enums and plural with flags, but I would like to hear some more pros and cons.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
这是直接来自 Microsoft 的:
http://msdn.microsoft .com/en-us/library/4x252001(VS.71).aspx
Here it is straight from Microsoft:
http://msdn.microsoft.com/en-us/library/4x252001(VS.71).aspx
其中一项建议来自 .NET 框架设计指南,第 59-60 页:
One recommendation comes from the .NET Framework Design Guidelines, page 59-60:
在 .NET Framework 中,大多数“普通”枚举(例如
DayOfWeek
)具有单数名称,而标志枚举(例如StringSplitOptions
、BindingFlags
)具有复数名称名称。这是有道理的,因为标志枚举的值可以表示多个项目,但对于非标志枚举,它只能表示单个项目。In the .NET Framework, most "normal" enums (e.g.
DayOfWeek
) have singular names and flag enums (e.g.StringSplitOptions
,BindingFlags
) have plural names. It makes sense, since a value of a flag enum can represent multiple items but for a non-flag enum, it can only represent a single item.是的。如果您有将枚举实现为类的心理体验,那么
事实上,您为该类型使用单一名称应该表明它
对此类枚举使用单数名称是有意义的。例如,
...
对于那些喜欢枚举中的复数的人,您会将其命名为 struct Weekdays 吗?
Yes. If you do the mental experience of implementing the enums as classes, then
the fact that you'd use a singular name for the type should reveal that it
makes sense to use singular names for such enums . E.g.,
...
For who prefers plurals in enums, would you name that
struct Weekdays
?一般来说,我认为枚举定义是类型定义,枚举的值是该类型可以具有的不同值;因此它有一个单一的名字:
In general, I consider an enum definition to be a type definition, with the values of the enum being the different values the type can have; therefore it gets a singular name:
Microsoft 建议对枚举使用单数名称,除非使用
Flags
属性。正如《框架设计指南》一书中所述,您不应在枚举类型名称后添加 Enum、Flags 等后缀,也不应在枚举值前添加缩写或首字母缩略词作为前缀,这在 VB 枚举中很常见。Microsoft recommends using a singular name for enumerations unless it uses the
Flags
attribute. And as taken from the Framework Design Guidelines book you should not suffix enumeration type names with Enum, Flags, etc. and you should not prefix enumeration values with an abbreviation or acronym as was common with VB enumerations back in the day.这是主观的,只要你保持一致,你使用什么并不重要(我个人使用单数,因为它是我的 Sql 约定的延续)
It's subjective and doesn't matter what you use, as long as you're consistent (personally I use singular as its a carry over from my Sql conventions)