C # Delegate 2 (delegate type)

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.