.NET枚举在最后一个字段中允许使用逗号 [英] .NET Enumeration allows comma in the last field

查看:112
本文介绍了.NET枚举在最后一个字段中允许使用逗号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么这个.NET枚举允许在最后一个字段中使用逗号?

这有什么特殊的含义吗?

  [FlagsAttribute] 
public enum DependencyPropertyOptions:byte
{
默认值= 1,
ReadOnly = 2,
可选= 4,
DelegateProperty = 32,
元数据= 8,
NonSerialized = 16,
}


解决方案

它没有什么特别的意义,只是编译器的工作原理,主要是因为这个原因:

  [FlagsAttribute] 
public enum DependencyPropertyOptions:byte
{
默认值= 1,
ReadOnly = 2,
可选=
DelegateProperty = 32,
元数据= 8,
非串行化= 16,
// EnumPropertyIWantToCommentOutEasily = 32
}
/ pre>

通过评论请求:Thi的信息直接出自 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.

这篇关于.NET枚举在最后一个字段中允许使用逗号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆