<分区>
这可能已经有人问过,但很难搜索。
[Something]
和 [SomethingAttribute]
有什么区别?
以下两个编译:
[DefaultValue(false)]
public bool Something { get; set; }
[DefaultValueAttribute(false)]
public bool SomethingElse { get; set; }
除了外观之外,它们之间还有什么区别吗?使用它们的一般准则是什么?
<分区>
这可能已经有人问过,但很难搜索。
[Something]
和 [SomethingAttribute]
有什么区别?
以下两个编译:
[DefaultValue(false)]
public bool Something { get; set; }
[DefaultValueAttribute(false)]
public bool SomethingElse { get; set; }
除了外观之外,它们之间还有什么区别吗?使用它们的一般准则是什么?
最佳答案
没有功能上的区别。 [Something]
只是 [SomethingAttribute]
的简写语法。
来自 MSDN :
By convention, all attribute names end with Attribute. However, several languages that target the runtime, such as Visual Basic and C#, do not require you to specify the full name of an attribute. For example, if you want to initialize System.ObsoleteAttribute, you only need to reference it as Obsolete.
关于c# - [Something] 和 [Something Attribute] 有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28440691/