Probe into the source--system.delegate of class library

Source: Internet
Author: User
Tags mscorlib

One, MSDN description

Delegate class: Represents a delegate, which is a data structure that references a static method or a reference class instance and an instance method of that class. (Does it feel like a function pointer in C language:) )

Namespaces: System

Assembly: mscorlib.dll

Speaking of Delegate, we must talk about Multicastdelagate.

Multicastdelagate class: Represents a multicast delegate, that is, a delegate whose invocation list can have more than one element.

Namespaces: System

Assembly: mscorlib.dll

Inheritance Relationship:

Note:

1. The Delegate class is the base class for the delegate type

2. MulticastDelegate inherits from delegate (this is nonsense, the above inheritance is so obvious)

3. MulticastDelegate has a list of delegates with a link, which is called the invocation list (virtual function table)

4. If an exception occurs when a delegate in the MulticastDelegate's delegate list executes, the delegate after the delegate does not execute

5. The relationship between delegate and delegate and Multicastdelagate in C #:

Marking a method with the delegate keyword in C # The compiler will automatically generate a class that inherits from System.MulticastDelegate, with the method name Class name, and adds the BeginInvoke and EndInvoke methods

usingSystem; Public Delegate voidCustomdelaget (); //using the delegate keyword compiler will automatically generate a class that inherits from System.MulticastDelegate/*. class public auto ANSI sealed customdelaget extends [mscorlib]system.multicastdelegate{}//End of Class Custom Delaget*/classapp{Static voidMain () {customdelaget D=NewCustomdelaget (Invoke);    D.invoke (); }        Static voidInvoke () {}}
View Code

Ii. using Action and Func instead of custom delegates

The Action represents a delegate that has no return value

Func represents a delegate with a return value

In other words, the action and Func assemblies are a bit weird, and func is like the action Assembly, taking action as an example

Action (T)--The Assembly for Action (T1,T2,T3,T4,T5,T6,T8) is mscorlib.dll

Action (T1,T2,T3,T4,T5,T6,T8,T9)-to-action (T1,T2,T3,..., T16) assembly is System.Core.dll

This gives people the first design of the class library of the people think up to 8 parameters is enough, and later found that 8 parameters are not enough, and added 8 in the System.Core.dll under the feeling

Third, asynchronous

1. Delegate-based asynchronous (traditional async)

2. Event-based Asynchronous

Not finished

Probe into the source--system.delegate of class library

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.