You could do a simple
Func<>
statement like so:
public static void TestArray(List<int> numbers, Func<int, bool> check)
{
foreach (int i in numbers)
{
if (IsAMatch(i,check))
{
Console.Write(" " + i);
}
}
Console.WriteLine();
}
public static bool IsAMatch(int valueToCheck, Func<int, bool> check)
{
return check(valueToCheck);
}
Then you could call it like so:
var intCollection = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
TestArray(intCollection, x => x % 2 == 0);
TestArray(intCollection, x => x % 2 != 0);
TestArray(intCollection, x => x {gt} 6);
* Having issues with the greater than in the last statement