I understand how to use delegates and I am okay with lambda expressions to make use of predicates. I've come to a point where I want to implement a method that uses a predicate as an argument and can't figure out how to reference the predicate to find the matches in my collection:
private static T FindInCollection<T>(ICollection<T> collection, Predicate<T> match)
{
foreach (T item in collection)
{
//So how do I reference match to return the matching item?
}
return default(T);
}
I want to then reference this using something akin to:
ICollection<MyTestClass> receivedList = //Some list I've received from somewhere else
MyTestClass UsefulItem = FindInCollection<MyTestClass>(receivedList, i => i.SomeField = "TheMatchingData");
If anyone can give me an explanation or point me to a reference regarding implementation of predicates, I'd appreciate it. The documentation out there seems to all relate to passing predicates (which I can do just fine), not actually implementing the functionality that uses them...
Thanks