How is it possible that C# attributes have "Attribute" in their name (e.g. DataMemberAttribute
) but are initialized without this suffix? e.g.:
[DataMember]
private int i;
How is it possible that C# attributes have "Attribute" in their name (e.g. DataMemberAttribute
) but are initialized without this suffix? e.g.:
[DataMember]
private int i;
It's a convention in the C#-compiler. Like it says on the MSDN-page on 'Using Attributes':
It works the same way in VB.NET.
this is the same thing.
[XAttribute] == [X]
from MSDN:
we can read also:
According to the C# Language Specification,
This is a shortcut provided by the C# compiler and by no means a CLR feature. Another example of special treatment of attributes by the compiler is an ObsoleteAttribute attribute: this one forces a compiler to issue a warning/error, but it has no special meaning for the CLR.
As for how attributes are resolved, see the link above. To sum it up:
A "verbatim identifier" is an identifier with an
@
prefix.Continuing with MSDN: