Using Attribute Parameters

Attribute parameters enable you to initialize an attribute with information specific to the code being written. Since an attribute is really another object, the parameters act the same as parameters for instance constructors. The main difference is that it's also possible to initialize public attribute fields and parameters at the same time.

There are two types of parameters: positional and named. Parameters can include only positional, only named, or a combination of both positional and named. Positional attributes are mandatory and always come before named attributes. The following sections go into more detail on each of these attribute parameter types.

Positional Parameters

Positional parameters correspond to the ...

Get C# Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.