GurdeepS
GurdeepS

Reputation: 67283

Trouble with Action<T1, T2> and passing multiple parameters

I have this code:

        s(x => x.Open());

s is a method which calls one parameter, which is perfectly fine, like so:

 public void s(Action<p1> action) {}

Ignoring the naming conventions, if I make the method like the below:

 public void s(Action<p1, p2> action) {}

How do I pass in more than one parameter? Out of interest, is there any way to use the params keyword with Action<>?

Also, I am using C# 4.0 so I would be interested to see how it can help me in an way.

Thanks

Upvotes: 4

Views: 3050

Answers (2)

JaredPar
JaredPar

Reputation: 755557

If you want to pass multiple parameters to a lambda expression in C# you need to enclose the parameters with parens. For example

s( (x,y) => x.Open(y) );

Upvotes: 9

Darin Dimitrov
Darin Dimitrov

Reputation: 1039498

s((x, y) => ...);

Upvotes: 2

Related Questions