为什么这个 .NET 枚举允许在最后一个字段中有一个逗号?
这有什么特殊意义吗?
[FlagsAttribute]
public enum DependencyPropertyOptions : byte
{
Default = 1,
ReadOnly = 2,
Optional = 4,
DelegateProperty = 32,
Metadata = 8,
NonSerialized = 16,
}
最佳答案
没有什么特别的意思,就是编译器的工作方式,主要是这个原因:
[FlagsAttribute]
public enum DependencyPropertyOptions : byte
{
Default = 1,
ReadOnly = 2,
Optional = 4,
DelegateProperty = 32,
Metadata = 8,
NonSerialized = 16,
//EnumPropertyIWantToCommentOutEasily = 32
}
根据评论请求:此信息直接来自 C# Specification (Page 355/Section 17.7)
Like Standard C++, C# allows a trailing comma at the end of an array-initializer. This syntax provides flexibility in adding or deleting members from such a list, and simplifies machine generation of such lists.
关于c# - .NET 枚举允许在最后一个字段中使用逗号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2147333/