In the CLR environment, several commonly used delegate actions, actions, Func, and Predicate are provided. Generally, when delegate is used, try not to define another delegate by yourself. The built-in system can meet most of the requirements and make the Code conform to the specifications. 1. The method encapsulated by ActionAction has no parameters and no return value. The declared prototype is: 1 public delegate void Action (). Usage: Copy code 1 public void Alert () 2 {3 Console. writeLine ("this is a warning"); 4} 5 6 Action t = new Action (Alert); // instantiate an Action delegate 7 t (); copy the Code. If the statements in the delegate method are short, you can also use the Lambd expression to define the method in the delegate, as shown in the following code: 1 Action t = () => {Console. writeLine ("this is a warning") ;}; 2 t (); 2. Action <T> is a generic implementation of Action and no return value, however, up to 16 parameters can be input. The declared prototype of the two parameters is: 1 public delegate void Action <in T1, in T2> (T1 arg1, T2 arg2). The usage is as follows: copy code 1 private void ShowResult (int a, int B) 2 {3 Console. writeLine (a + B); 4} 5 6 Action <int, int> t = new Action <int, int> (ShowResult ); // The delegate with two parameters but no return value is 7 t (2, 3). You can also copy the code and directly define the method in the delegate using the Lambd expression. The Code is as follows: 1 Action <int, int> t = (a, B) => {Console. writeLine (a + B) ;}; 2 t (2, 3); 3. The Func <T> delegate always has a return value, the type of the return value is the last one in the parameter. You can either input a parameter or a maximum of 16 parameters, but you can enter a maximum of 16 parameters. The declaration prototype of the return value of two parameters is: 1 public delegate TResult Func <in T1, in T2, out TResult> (T1 arg1, T2 arg2); usage: copy the Code 1 public int Compare (int a, int B) 2 {3 return a> B; 4} 5 6 Func <int, int, bool> t = new Func <int, int, bool> (Compare ); // input two int parameters and return the bool value 7 bool result = t (2, 3). Copy the code and use the Lambd expression to directly define the method in the delegate, the Code is as follows: 1 Func <int, int, bool> t = (a, B) =>{ return a> B ;}; 2 bool result = t (2, 3 ); 4. the Predicate <T> delegate defines a set of conditions and determines whether the specified object meets these conditions. The return value is always of the bool type and the declared prototype is: 1 public delegate bool Predicate <in T> (T obj); usage: Copy code 1 public bool Match (int val) 2 {3 return val> 60; 4} 5 6 Predicate <int> t = new Predicate <int> (Match); // defines a comparison delegate 7 int [] arr = {13, 45, 26, 98, 3, 56, 72, 24}; 8 int first = Array. find (arr, t); // Find the first element in the array larger than 60 and copy the code. You can also use the Lambd expression to directly define the method in the delegate. The Code is as follows: 1 Predicate <int> t = val =>{ return val> 60 ;}; // defines a comparison delegate 2 int [] arr = {13, 45, 26, 98, 3, 56, 72, 24}; 3 int first = Array. find (arr, t); // Find the first element in the array greater than 60. Conclusion: if the method to be delegated has no parameters and no return values, you can think of Action with parameters but no return values. <T> if no parameter has a return value, and a parameter has a return value, you can think of Func <T>. return values of the bool type, this method is usually used in comparator. To delegate this method, you can use Predicate <T>