Entrust CLR to learn Lesson 15th

Source: Internet
Author: User

1. Delegation is the encapsulation of methods (static methods and instance methods). After we pass a method to the delegate

The delegate points to a specific method. Writing a parameter in the delegate is like writing a parameter in the method and pointing to

Same method.

2. declare that the delegate compiler will delegate this lineCodeGeneration, four methods: A constructor, invoke (and Source

The prototype specified in the Code is the same, with different names and virtual methods. parameters, return values, andSource codeConsistent definitions

), Begininvoke, and endinovke (begininvoke and endinovke are used for asynchronous callback ).

3. Therefore, each delegate has a constructor, And the constructor accepts two parameters: one object reference, one

The integer that points to the callback method.

4. Therefore, all delegates are inherited from multicastdelegate, while multicastdelegate inherits from

Delegate and delegate inherit from the object. It has three important fields: _ target (Object Class

Type), _ methodptr (int32), an internal number (to be precise, the field type is system.

Intptr, which is mainly used to indicate pointers or handles). CLR uses it to identify the callback method. , _ Prev

(Multicastdelegate) points to another delegate object. This field is usually null.

5. Compare whether the delegate uses equals, and check whether their _ traget, _ methodptr are equal and

_ Prev points to the linked list with the same length. If all matches, true is returned; even if it points to the same callback target/callback

Delegate objects of methods, even if they reference two different objects, but they all reference the same

So true is returned.

6. The delegate class defines three static methods to help us operate the delegate linked list and two combine

, A remove, all of which return value type is delegate static method.

7. + = call the delegate. Combine method, and use the-= delimiter method delegate. Remove.

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.