Predicate<(Of <(T>)>) 委托
表示定义一组条件并确定指定对象是否符合这些条件的方法
public delegate bool Predicate<in T>( T obj )
此委托由 Array 和 List<(Of <(T>)>) 类的几种方法使用,用于在集合中搜索元素。
用户不需要显式创建委托,也不需要指定泛型方法的类型参数。 编译器会根据您提供的方法参数确定必需的类型。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 using System; 2 using System.Drawing; 3 4 public class Example 5 { 6 public static void Main() 7 { 8 // Create an array of five Point structures. 9 Point[] points = { new Point(100, 200), 10 new Point(150, 250), new Point(250, 375), 11 new Point(275, 395), new Point(295, 450) }; 12 13 // To find the first Point structure for which X times Y 14 // is greater than 100000, pass the array and a delegate 15 // that represents the ProductGT10 method to the static 16 // Find method of the Array class. 17 Point first = Array.Find(points, ProductGT10); 18 19 // Note that you do not need to create the delegate 20 // explicitly, or to specify the type parameter of the 21 // generic method, because the C# compiler has enough 22 // context to determine that information for you. 23 24 // Display the first structure found. 25 Console.WriteLine("Found: X = {0}, Y = {1}", first.X, first.Y); 26 } 27 28 // This method implements the test condition for the Find 29 // method. 30 private static bool ProductGT10(Point p) 31 { 32 if (p.X * p.Y > 100000) 33 { 34 return true; 35 } 36 else 37 { 38 return false; 39 } 40 } 41 } 42 43 /* This code example produces the following output: 44 45 Found: X = 275, Y = 395 46 */