The CarDelegateWithLambdas project can be found under the Chapter 11 subdirectory.
Lambda Expressions with Multiple (or Zero) Parameters
Each of the lambda expressions you have seen here processed a single parameter. This is not a
requirement, however, as a lambda expression may process multiple arguments or provide no
arguments whatsoever. To illustrate the first scenario, create a final Console Application named
LambdaExpressionsMultipleParams. Next, assume the following incarnation of the SimpleMath type:
public class SimpleMath
{
public delegate void MathMessage(string msg, int result);
private MathMessage mmDelegate;
public void SetMathHandler(MathMessage target)
{mmDelegate = target; }
public void Add(int x, int y)
{
if (mmDelegate != null)
mmDelegate.Invoke("Adding has completed!", x + y);
}
}
Notice that the MathMessage delegate is expecting two parameters. To
represent them as a
lambda expression, our Main() method might be written as follows:
static void Main(string[] args)
{
Do'stlaringiz bilan baham: