I have a class that takes an action in it's constructor.
Example:
public CustomClass(Action<Path> insert)
{
// logic here...
}
I currently instantiate this class using the following line of code:
var custom = new CustomClass((o) => LayoutRoot.Children.Add(o));
I want to modify the custom class to include an additional constructor, such as the following:
public CustomClass(Action<Path, TextBlock> insert)
{
// logic here...
}
However, my knowledge of lambda expressions is pretty basic, so I can't figure out how to instantiate the custom class, passing two parameters in the action to the new constructor.
Any help would be greatly appreciated.
Thanks.
In order to pass 2 parameters to the action, just define the insert action as an
Action<T,T2>
and when you call it do it like this:In Lamba you can pass two parameters as such:
Either you are asking
or
The second constructor will take an delegate that receives 2 parameters. So you can do something like
You can create a lambda expression that takes more than one parameter by surrounding the parameter list with parentheses and comma separate the parameters:
If you need to perform more than one statement in a lambda, you can surround the body of the lambda with braces:
You can learn more about lambda syntax here on MSDN.