Array - Find
A T[] extension method that searches for the first match.
public static void Main() { Point[] points = { new Point(100, 200), new Point(150, 250), new Point(250, 375), new Point(275, 395), new Point(295, 450), new Point(405, 425), new Point(375, 850) }; // C# Extension Method: Array - Find Point first = points.Find(ProductGT10); Console.WriteLine("Found: X = {0}, Y = {1}", first.X, first.Y); } // Return true if X times Y is greater than 100000. private static bool ProductGT10(Point p) { return p.X * p.Y > 100000; }
View Source
using System; public static partial class Extensions { /// <summary> /// A T[] extension method that searches for the first match. /// </summary> /// <typeparam name="T">Generic type parameter.</typeparam> /// <param name="array">The array to act on.</param> /// <param name="match">Specifies the match.</param> /// <returns>A T.</returns> public static T Find<T>(this T[] array, Predicate<T> match) { return Array.Find(array, match); } }