Often see Func<int, bool> This way of writing, see This is no mind to look down. We still need to be quiet when we learn technology.
The Func to func<int,bool> goes to the definition to see its explanation:
//Summary:
// Encapsulates a method that has one parameter and returns the type value specified by the TResult parameter.
//
//Parameters:
// arg:
// The parameters of the method encapsulated by this delegate.
//
//Type parameters:
// T:
// The parameter type of the method encapsulated by this delegate.
//
// TResult:
// The return value type of the method encapsulated by this delegate.
//
//Return results:
// The return value of the method encapsulated by this delegate.
[Typeforwardedfrom ("System.core, version=3.5.0.0, Culture=neutral, publickeytoken= b77a5c561934e089 ")]
public delegate TResult Func<in T, out tresult> (t arg);
In t represents the input parameter 1 out TResult represents the output parameter 2 again see the return value is TResult 3 constructor method required parameter is T 4
1 Compare with 4,2 and 3, what did you find?! Parameter type, right. 5
Func is a delegate, the delegate can be stored inside the method, then we have to build a matching method: Take func<int,bool> as an example:
private bool IsNumberLessThen5 (int number)
{return number < 5;}
Func<int,bool> f1 = IsNUmberLessThen5;
Call: BOOL flag= F1 (4);
Here is the specific code:
Using System; Using System.Collections.Generic; Using System.Linq; Using System.Linq.Expressions; Using System.Text; Using System.Threading.Tasks;
Namespace ConsoleApplication1 {class Program {static void Main (string[] args) {Func <int, bool> f1 = IsNumberLessThen5; BOOL flag = f1 (4); Console.WriteLine (flag);
//The following are other uses, similar to the ISNUMBERLESSTHEN5 function. It's just a different notation. func<int, bool> f2 = i = i < 5; func<int, bool> f3 = (i) + = {return I < 5 ; }; Func<int, bool> f4 = delegate (int i) {return I < 5; }; flag = F2 (4); Console.WriteLine (flag); flag = F3 (4); Console.WriteLine (flag); flag = f4 (4); Console.WriteLine (flag);
Console.ReadLine (); }
private static bool IsNumberLessThen5 (int number) {if (number < 5) return true; return false; } } }
Transfer from Pnljs delegate (func<int,bool>)