Problem with action <T1, T2> and passing several parameters

I have this code:

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

s is a method that calls a single parameter that looks great like this:

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

Ignoring naming conventions if I make a method as follows:

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

How to pass several parameters? Of interest, is there a way to use the params keyword with Action <>?

I also use C # 4.0, so I would be interested to know how this can help me.

thanks

+4
source share
2 answers

If you want to pass multiple parameters to a lambda expression in C #, you need to wrap the parameters with parens. for instance

 s( (x,y) => x.Open(y) ); 
+9
source
 s((x, y) => ...); 
+2
source

Source: https://habr.com/ru/post/1305317/


All Articles