Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass action with two parameters using Lambda expression to method?

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.

like image 744
Chris Avatar asked Jan 12 '10 16:01

Chris


1 Answers

In Lamba you can pass two parameters as such:

(x, y) => { x.DoSomething(); y.DoSomethingElse(); }
like image 152
Tony The Lion Avatar answered Sep 23 '22 22:09

Tony The Lion