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 lik开发者_运维问答e 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
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) );
s((x, y) => ...);
精彩评论