What is a Predicate <T> delegate?
What is a Predicate delegate? It would be great help if someone explain it with practical.
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
naura paxRank #2,843 · 502 reputationPosted Jul 6, 2009, 5:25 AM EDT
Predicate
Suppose you have a List of your user defined objects.
Class Person { string name; int id;}
and you have create a list of class Persons : List
then you might want to set your own rule for finding a particular object from the entire list
So you'll have to pass a Predicat
where you define your own method (either anynomous or declared)
int currentID=GetID();// Your application code.
.FindAll(delegate(Person obj) { return obj.Id== currentID; }));
Here is the formal definition :
The Predicate<(Of <(T>)>) is a delegate to a method that returns true if the object passed to it matches the conditions defined in the delegate. The elements of the current List<(Of <(T>)>) are individually passed to the Predicate<(Of <(T>)>) delegate, moving forward in the List<(Of <(T>)>), starting with the first element and ending with the last element. Processing is stopped when a match is found.
Hope it helps.