Understanding of predicate

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.