Array - FindAll
A T[] extension method that searches for the first all.
public static void Main() { int[] values = GetArray(50, 0, 1000); int lBound = 300; int uBound = 600; // C# Extension Method: Array - FindAll int[] matchedItems = values.FindAll(x => x >= lBound && x <= uBound); for (int ctr = 0; ctr < matchedItems.Length; ctr++) { Console.Write("{0} ", matchedItems[ctr]); if ((ctr + 1) % 12 == 0) Console.WriteLine(); } } private static int[] GetArray(int n, int lower, int upper) { Random rnd = new Random(); List<int> list = new List<int>(); for (int ctr = 1; ctr <= n; ctr++) list.Add(rnd.Next(lower, upper + 1)); return list.ToArray(); }
View Source
using System; public static partial class Extensions { /// <summary> /// A T[] extension method that searches for the first all. /// </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>The found all.</returns> public static T[] FindAll<T>(this T[] array, Predicate<T> match) { return Array.FindAll(array, match); } }