Information Technology Reference
In-Depth Information
Parameters
Except in the case of array parameters, the parameter list of an anonymous method must
match that of the delegate in the following three characteristics:
Number of parameters
Types of the parameters
Mod iers
You can simplify the parameter list of an anonymous method by leaving the parentheses
empty or omitting them altogether, if
both
of the following are true:
The delegate's parameter list does not contain any
out
parameters.
The anonymous method does not use
any
parameters.
For example, the following code declares a delegate that does not have any
out
parame-
ters, and an anonymous method that does not use any parameters. Since both conditions are
met, you can omit the parameter list from the anonymous method.
delegate void SomeDel ( int X ); // Declare the delegate type.
SomeDel SDel = delegate // Parameter list omitted
{
PrintMessage();
Cleanup();
};