Introduction
A Predicate delegate is a generic type of delegate built into the language. It is a delegate, similar to Func and Action delegates. It represents a method with a set of criteria that checks to see if the passed parameter meets those criteria. A predicate delegate method must accept one input parameter and return a boolean value, either true or false.
Syntax
public delegate bool Predicate <in T>(T obj);
T is the type of the object, and obj is the object that will be compared against the criteria provided within the method represented by the Predicate delegate. The Predicate delegate is specified in the System namespace. It has one input argument and a boolean return type. Predicate, like the other delegate types, can be used with any method, anonymous method, or lambda expression.
Example
class PredicateExample {
public static bool fun(string mystring)
{
if (mystring.Length < 7)
{
return true;
}
else
{
return false;
}
}
static public void Main()
{
Predicate<string> val = fun;
Console.WriteLine(val("This is an Example"));
}
}
Output: False