I have written a helper class which uses the Action - delegate as method parameter.
Like this:public void SomeMethod(Action<T> methodToExecute, T argument);
According to the MSDN you can declare max. 4 arguments on an action delegate: Action<T1,T2,T3,T4>
.
Now I'd like to call a method which needs 5! arguments. How could I do this?
The best solution would be something where I could use a dynamic number of method arguments.
Thanks
A delegate is a type safe and object oriented object that can point to another method or multiple methods which can then be invoked later.
You can pass methods as parameters to a delegate to allow the delegate to point to the method. Delegates are used to define callback methods and implement event handling, and they are declared using the “delegate” keyword. You can declare a delegate that can appear on its own or even nested inside a class.
The only difference between Action Delegates and Function Delegates is that Action Delegates does not return anything i.e. having void return type. An Action Delegate can also be initialized using the new keyword. Action<int> val = new Action<int>(myfun);
You can use the Action delegate type. Then you can use it like this: void MyAction() { } ErrorDBConcurrency(e, MyAction); If you do need parameters you can use a lambda expression.
Declare the action delegate you need, there's nothing magic about it:
public delegate void Action<T1, T2, T3, T4, T5>(T1 p1, T2 p2, T3 p3, T4 p4, T5 p5);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With