Information Technology Reference
In-Depth Information
The following code shows the declaration of the attribute class, as well as its application on
class MyClass . Notice that the constructor declaration lists only a single formal parameter. And
yet by using named parameters, you can give the constructor three actual parameters. The two
named parameters set the values of fields Ver and Reviewer .
public sealed class MyAttributeAttribute : System.Attribute
{
public string Description;
public string Ver;
public string Reviewer;
public MyAttributeAttribute(string desc) // Single formal parameters.
{ Description = desc; }
}
// Three actual parameters
[MyAttribute("An excellent class", Reviewer="Amy McArthur", Ver="7.15.33")]
class MyClass
{ ... }
Note If there are any positional parameters required by the constructor, they must be placed before any
named parameters.
Search WWH ::




Custom Search