What is a Predicate <T> delegate?
What is a Predicate delegate? It would be great help if someone explain it with practical.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
naura paxPosted Jul 6, 2009, 9:25 AM
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.