c# - Use delegate to write a method to take another method as an input parameter and the delegate should have unknown numbers of parameters -


Sorry my title is a bit confused and confused. I explain here in the details. In my program, there are four ways in which I simplify my interface only. Private static zero method A (type 1 parameter 1, type 2 parameter 2) Private static zero method B (type 1 Parameter 1, Type2 parameter, Type 3 parameter 3) Private Static Type 4 Methion C (Type 1 parameter 1, Type 2 parameter 2) Private Static Type 4 Method D (Type 1 parameter 1, Type 2 parameter, Type 3 parameter 3)

I for these methods I want to write a generic retrieval logic (I do not want to add every attempt again). Do something like (try the representative function break)} (exception preceding) {Thread.sleep} to do something like

  (for int retrieval = 0; retry  

What I am thinking is to write another method to use the function representative as an input and calculate the retry form as another input It's something like that. But these four ways signature are quite different. There are three input parameters (B, D) and some have two (A, C).

I have only one very The simple C # book and the example of its representative is with the same signature, it is not certain that we can have a representative with different numbers, so at least we can add method a, b and method c, d together .

If a representative does not have pass / output and we have one, b , C, D together and it would be much better.

to deal with the parameters , You can take a representative with your retry method parameter and you can use lambda while calling it. Something like this:

  Try again Zero (action verb) {for (try again int; 0; try again; reCrack; try again ++) {try { Action (); break; } Hold (Exception preceded by {Thread.sleep (5000); }}} ... Try again (() = & gt; Method A (P1, P2));  

For return value or return value, you have to take a action for try again () : zero Methods and other generic one, Func & lt; T & gt; Return values ​​by taking (and back to T ).


Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -