There are several use cases where it is useful for the caller to provide a function that returns trueor false. Type Predicate<T>is the way to do this. This is no different from Func<T, bool>(except Predicate<T>available in earlier versions of C #).
A simple (and far-fetched example):
string[] strings = new string[] { "hello", "goodbye", "how are you" };
Array.FindAll(strings, delegate(string s)
{
return s.StartsWith("h");
});
or, lambda style:
Array.FindAll(strings, s => s.StartsWith("h"));
The method FindAllreturns an array of all elements matching the condition. In this case, all lines starting with "h". Predicate s.StartsWith("h").
, Array , , , . . , , - , . , Predicate.
"" . Func<Predicate<T>> , , Predicate<T>. , , ? ?