Check if array contains elements that match the conditions defined by the specified predicate in CSharp
Description
The following code shows how to check if array contains elements that match the conditions defined by the specified predicate.
Example
/*from w ww.j a v a 2 s . 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.Exists(myValues, myPredicate));
}
private static bool LenCheck(String s)
{
if (s.Length > 3)
{
return true;
}
else
{
return false;
}
}
}
The code above generates the following result.