In most cases they are the same. As already said you can typically use them interchangeable except when you have both DefaultValue
and DefaultValueAttribute
defined. You can use both of these without ambiguity errors by using the verbatim identifier (@
).
The C#LS section 17.2 makes this more clear:
[AttributeUsage(AttributeTargets.All)]
public class X: Attribute {}
[AttributeUsage(AttributeTargets.All)]
public class XAttribute: Attribute {}
[X] // Error: ambiguity
class Class1 {}
[XAttribute] // Refers to XAttribute
class Class2 {}
[@X] // Refers to X
class Class3 {}
[@XAttribute] // Refers to XAttribute
class Class4 {}
This refers to the actual usage of the attribute. Of course if you require use of the type name such as when using typeof
or reflection, you'll need to use the actual name you gave the type.