为什么允许在最后一个字段逗号这个.NET枚举? 这是否有什么特殊的意义?
[的FlagsAttribute]
公共枚举DependencyPropertyOptions:字节
{
默认值= 1,
只读= 2,
可选= 4,
DelegateProperty = 32,
元数据= 8,
非序列化= 16,
}
解决方案
这没有什么特别的意思,只是方式的编译器工作,这是主要是这个原因:
[的FlagsAttribute]
公共枚举DependencyPropertyOptions:字节
{
默认值= 1,
只读= 2,
可选= 4,
DelegateProperty = 32,
元数据= 8,
非序列化= 16,
// EnumPropertyIWantToCommentOutEasily = 32
}
通过评论的请求:本信息来直接从 C#规范(页363 /第19.7节)
像标准C ++,C#允许一个尾随逗号数组的初始化函数的末尾。此语法提供了灵活性,增加或删除这样一个列表的成员,并简化了机器产生这样的列表。
Why is this .NET enumeration allowed to have a comma in the last field? Does this have any special meaning?
[FlagsAttribute]
public enum DependencyPropertyOptions : byte
{
Default = 1,
ReadOnly = 2,
Optional = 4,
DelegateProperty = 32,
Metadata = 8,
NonSerialized = 16,
}
解决方案
It has no special meaning, just the way the compiler works, it's mainly for this reason:
[FlagsAttribute]
public enum DependencyPropertyOptions : byte
{
Default = 1,
ReadOnly = 2,
Optional = 4,
DelegateProperty = 32,
Metadata = 8,
NonSerialized = 16,
//EnumPropertyIWantToCommentOutEasily = 32
}
By comment request: This info comes straight out of the C# Specification (Page 363/Section 19.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.