CSharp · Console
// C# Extension Method
// Doc: https://csharp-extension.com/en/method/1002635/array-findall
// @nuget: Z.ExtensionMethods
using System;
using System.Collections.Generic;
public class Program
{
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();
}
}