c# - [Something] 和 [Something Attribute] 有什么区别

标签 c# .net-attributes

<分区>

这可能已经有人问过,但很难搜索。

[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/

相关文章:

c# - 使用 C# 在 Azure 存储中创建容器

c# - 如何在不使用 HttpContext.Current 的情况下获取 ASP.NET Web 应用程序的物理位置?

c# - 你会如何从数组中删除空白条目

c# - 获取枚举值的属性

c# - 为什么 C# 禁止泛型属性类型?

c# - [STAThread] 是做什么的?

c# - 无法通过 C# 连接到 ManagementScope。拒绝访问

c# - 属性中的名称

c# - 属性规范中奇怪的歧义(两个 using 指令)

c# - 用于家庭开发的免费云数据库服务