We should all be clear that before using a delegate, we should first define a delegate type, as shown below:
Delegate int mydelegate (int A, int B );
Mydelegate MD = NULL;
Since it is called the delegate type.MydelegateIt is actually a class. The above writing method is just a simple method of scaling down,In fact, all the custom delegates are inherited fromSystem. multicastdelegateClass.
We can find that there are still four methods, one being constructor.
Multicastdelegate class
multidelegate A class is a special class ( special class ), and system. deleGate like a class, this class can only be inherited by the compiler and built-in tool classes. Our custom classes cannot inherit from this class explicitly.
multidelegate the class can contain a delegate linked list. In this table, it can contain one or more elements (each element is a delegate). We can call this table a call chain. When we call a multidelegate In the multidelegate the delegate in the call chain is called serially. In this way, we can only call one Party method, multiple methods with the same signature it is called in serial mode at the same time. The description of multicast delegation will be explained later.
Invoke Method
To explainInvokeMethod. Let's review how a delegate calls a method,CodeAs follows:
Int c = This. MD (A, B );
When we call a delegate and execute the method pointed to by the delegate, it basically calls itsInvokeMethod. In fact, we can directly call itsInvokeThe Code is as follows:
Int c = This. md. Invoke (A, B );
In addition, with invoke method begininvoke, Yes invoke An asynchronous call to a method, and endinvoke it is the processing method after the asynchronous call is completed.