Check if every element in the array matches the conditions defined by the specified predicate in CSharp
Description
The following code shows how to check if every element in the array matches the conditions defined by the specified predicate.
Example
//from ww w . ja v a 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.