Understanding: A delegate defines a type of method, which is equivalent to a List of variables. Variables of the same type can be added to the List in sequence, and methods of the same type can also be added to the delegate in sequence.
analyze:
- What is the type of method: Methods with the same return value type and parameters can be regarded as the same type.
- How a delegate defines the type of a method:
Getting started:
In the above image, via delegate The keyword defines a delegate type named DelegateDemo.
1. Declare a delegate type variable through the delegate type DelegateDemo.
2. Declare some methods according to the type of method defined by the delegate
3. Specific use of the delegate
Summary: The above This is my understanding of delegation and how to use delegation. Delegation and generic delegation in C# are not explained here. If you want to continue to understand, you can check out other information.
Attached: complete picture