The delegate int the Transform (int x);
Defines a only a parameter called the Transform and parameter type for the int return values for int type of entrust; Then we can all have only one parameter and the parameter type for the int return values for int type of method (function) added to the delegate,
Private int Square1 (int x)
{
Return * x x;
}
Private int Square2 (int x)
{
Return x x x x x
}
The Transform t=Square1;
T +=Square2;
So can I understand like this:
The above steps defined in the delegate:
The delegate int the Transform (int x); Defines a generic equivalent to me: List
Transfrom t=Square1; Equivalent: listString=new List
T +=Square2; The equivalent of listString. Add (" the second string ");
When we call the delegate:
T (3); Is the equivalent of a foreach (string I in listString);
Actually, I want to say is: I think trust is equivalent to a deposit a kind of "array" method (or generic), when the delegate is invoked, is equivalent to the "array" foreach (or generic) all of the methods, and then each execution again, and "+=" is equivalent to the Add elements in the "array";" -="is equivalent to the" array "Remove elements, specified in the
This I understand right?
CodePudding user response:
Delegate can be understood as the single method in the Java interface, Function pointer in C/C + +, the types of the Function in JS, JS in the Function can be directly used as an example of the Function, and in C #, entrusted to explicitly define the same type of indirect references to specific methods, as for +=, -=is your understanding about it,CodePudding user response:
then each perform again, and "+=" is equivalent to the Add elements in the "array";" -="is equivalent to the" array "Remove elements specified in theYes, understand a problem,
The old way is before the Add {} Remove {}, if I remember correctly, is so binding events,
And if you assignment 2 times, is indeed will run 2 times,