Information Technology Reference
In-Depth Information
Positional and Named Parameters in Constructors
So far, the parameters you've seen with attribute constructors have been like the parameters
for regular class constructors. As with regular constructors, the actual parameters of attribute
constructors must be placed in the correct order, matching the formal parameters in the class
declaration. These are called positional parameters , because the compiler knows which actual
parameter goes with which formal parameter by its position in the parameter list.
But attribute constructors can also have another type of actual parameter, called a named
parameter .
￿
A named parameter consists of the name of a field or property, followed by an equals
sign, followed by an initializing value.
￿
A named parameter sets the value of an attribute's field or property.
Named parameters are actual parameters. There is nothing different in the declaration of
the formal parameters of the constructor. The only difference is in the list of actual parameters
that is supplied when the attribute is applied.
The following code shows the application of an attribute using a positional parameter and
two named parameters.
Positional parameter Equals sign Equals sign
[MyAttribute("An excellent class", Reviewer="Amy McArthur" , Ver="0.7.15.33" )]
Named parameter Named parameter
Search WWH ::




Custom Search