Searchs by predicate and return the zero-based index of the last occurrence within the entire Array in CSharp
Description
The following code shows how to searchs by predicate and return the zero-based index of the last occurrence within the entire Array.
Example
using System;//w w w .ja v a 2 s . com
public class MainClass
{
public static void Main()
{
string[] myValues ={
"1234", "19", "3456",
"3456", "200","5678",
"6543", "9876"
};
Predicate<string> myPredicate = LenCheck;
Console.WriteLine(Array.FindLastIndex(myValues, myPredicate));
}
private static bool LenCheck(String s)
{
if (s.Length > 3)
{
return true;
}
else
{
return false;
}
}
}
The code above generates the following result.