A delegate is a class that defines the type of method so that it can be passed as an argument to another method. An event is a special commission.
1. Statement of entrustment
(1). delegate
delegate
Delegate has at least 0 parameters and a maximum of 32 parameters, and can have no return value or specify a return value type.
For example, public delegate int MethodtDelegate(int x, int y); Indicates that there are two parameters, and returns an int type.
(2). Action
Action is a generic delegate with no return value.
Action represents a delegate with no parameters and no return value
Action<int,string> indicates a delegate with an incoming parameter int and no return value for string
Action<int,string,bool> indicates a delegate with incoming parameters int,string,bool without return values
Action<int,int,int,int> means that there are 4 int-type parameters passed in and there is no return value
Action has at least 0 parameters and a maximum of 16 parameters, with no return value.
Example:
(3). Func
Func is a generic delegate with a return value
Func<int> means a delegate with no parameters and returns an int value
Func<object,string,int> represents a delegate with the incoming parameter as object and the string returns an int value
Func<object,string,int> represents a delegate with the incoming parameter as object and the string returns an int value
Func<T1,T2,,T3,int> represents a delegate with the incoming parameter T1, T2, ,T3 (generic) returning an int value
Func has at least 0 parameters and a maximum of 16 parameters, which are returned according to the return value generic. There must be a return value, not void
Example:
(4) .predicate
predicate is a generic delegate that returns a bool type
predicate<int> represents a delegate with the incoming parameter int returning bool
Predicate has and only one parameter, and the return value is fixed to bool
Example:
|