Attributes enable the programmer to give certain declarative information to the elements in their class. These elements include the class itself, the methods, the fields, and the properties. You can choose to use some of the useful built-in attributes provided with the .NET platform, or you can create your own. Attributes are specified in square brackets ( [. . .] ) before the class element upon which they’re implemented. Table 6 shows some useful attributes provided with .NET.
Table 6 Useful Built-in Attributes
NAME |
DESCRIPTION |
EXAMPLE |
DllImport |
Imports a native DLL |
[DllImport(“winmm.dll”) ] |
Serializable |
Makes a class serializable |
[Serializable] |
Conditional |
Includes/omits a method based on condition |
[Conditional(Diagnostic”)] |