C# Array FindAll
Description
Array FindAll
retrieves all the elements that
match the conditions defined by the specified predicate.
Syntax
Array.FindAll
has the following syntax.
public static T[] FindAll<T>(
T[] array,
Predicate<T> match
)
Parameters
Array.FindAll
has the following parameters.
T
- The type of the elements of the array.array
- The one-dimensional, zero-based Array to search.match
- The Predicatethat defines the conditions of the elements to search for.
Returns
Array.FindAll
method returns
Example
//from ww w . j av a 2s . c o m
using System;
public class MainClass
{
public static void Main()
{
string[] myValues ={
"1234", "19", "3456",
"3456", "200","5678",
"6543", "9876"
};
Predicate<string> myPredicate = LenCheck;
Console.WriteLine(Array.FindAll(myValues, myPredicate));
}
private static bool LenCheck(String s)
{
if (s.Length > 3)
{
return true;
}
else
{
return false;
}
}
}
The code above generates the following result.