C# Array TrueForAll
Description
Array TrueForAll
determines whether every element
in the array matches the conditions defined by the specified predicate.
Syntax
Array.TrueForAll<T>
has the following syntax.
public static bool TrueForAll<T>(
T[] array,
Predicate<T> match
)
Parameters
Array.TrueForAll<T>
has the following parameters.
T
- The type of the elements of the array.array
- The one-dimensional, zero-based Array to check against the conditionsmatch
- The Predicatethat defines the conditions to check against the elements.
Returns
Array.TrueForAll<T>
method returns true if every element in array matches the conditions defined by the specified
predicate; otherwise, false. If there are no elements in the array, the return
value is true.
Example
// w w w .j a va 2s. co 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.TrueForAll(myValues, myPredicate));
}
private static bool LenCheck(String s)
{
if (s.Length > 3)
{
return true;
}
else
{
return false;
}
}
}
The code above generates the following result.