Built-in Attributes

You use attributes to connect metadata, including compiler directives, to an element in your code. There are plenty of attributes built into C#, and we've already seen a number of them in this book. For example, this attribute lets you indicate that a method is a Web method, accessible from a Web service:


This attribute lets you indicate that a class can be serialized:


This attribute indicates that you want to import a DLL; in this case, kernel32.dll:

[DllImport("kernel32", SetLastError=true)]

Note the syntax in this case. We're passing text to the DLLImport attribute, followed by the expression SetLastError=true.

We also saw that you can use attributes to specify metadata about specific elements, ...

Get Microsoft® Visual C#® .NET 2003 Kick Start now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.