DebuggerDisplayAttribute和DebuggerDisplay之间的区别

Bri*_*ian 3 .net attributes

[DebuggerDisplayAttribute("{_name}")]
Run Code Online (Sandbox Code Playgroud)

VS

[DebuggerDisplay("{_name}")]
Run Code Online (Sandbox Code Playgroud)

有区别吗?一个是别人的别名吗?当使用名为foo的属性时,VS是否自动检查名为fooAttribute的类?

Jak*_*son 9

它们是相同的,无论你是否在最后编写属性,C#编译器都能够解析类型.


Dre*_*kes 5

他们是一样的.您倾向于在生成的代码中看到完全限定的名称,尤其是通过CodeDom输出的名称.

你可以使用任何一个.编译器最终生成相同的东西.


AMi*_*ico 5

没有区别.命名类的标准约定是附加单词Attribute,如下所示:

public class AlertAttribute : Attribute {}
Run Code Online (Sandbox Code Playgroud)

使用属性时,标准约定是消除单词,如:

[Alert()]
Run Code Online (Sandbox Code Playgroud)

来自属性(C#和Visual Basic),网址http://msdn.microsoft.com/en-us/library/z0w1kczw.aspx

按照惯例,所有属性名称都以单词"Attribute"结尾,以区别于.NET Framework中的其他项.但是,在代码中使用属性时,不需要指定属性后缀.例如,[DllImport]等同于[DllImportAttribute],但DllImportAttribute是.NET Framework中属性的实际名称.