what is predicate? ( Note: The following excerpt from the C # technical documentation)
Summary: Represents a method that defines a set of conditions and determines whether the specified object conforms to those conditions.
Public delegate bool Predicate<in t> (T obj).
Parameter: obj: The object to be compared by the criteria defined in the method represented by this delegate.
Type parameter: T: The type of object to compare.
Returns the result: true if obj conforms to the condition defined in the method represented by this delegate;
It's not easy to understand, just look at an example:
list<string> list = new list<string> (); List. AddRange (new string[] {"ASP. NET course, "EE course", "PHP Course", "Data Structure Course"}); predicate<string> findpredicate = new predicate<string> (isbookcategory); list<string> bookcategory = list. FindAll (findpredicate);
static bool Isbookcategory (String str) { return str. EndsWith ("course")? True:false; }
Personal Understanding:
The role of the predicate delegate is just as the summary says: Represents a method that defines a set of conditions and determines whether the specified object conforms to those conditions.
A condition is specified by means of a delegate.
In the code: predicate instance findpredicate points to Method Isbookcatagory (), which defines a decision condition.
list<string> bookcategory = List. FindAll (findpredicate); The FindAll () method finds the condition that satisfies the findpredicate point.
Understanding of predicate