A predicate tends to return bool
, not an object. What are you going to return when the condition isn't met? Given your example, you don't really mean the function returns an object - you mean it takes an object and returns a bool
.
Note that if you're going to have a parameter in the lambda expression, you'll need to use a delegate which takes parameters too.
We really need more information before giving a definitive answer, but you might want something like:
void MethodTest(Func<HtmlImage, bool> predicate)
or
void MethodTest(Predicate<HtmlImage> predicate)
(Personally I like the descriptive nature of using a named delegate, but others prefer to use Func
/Action
for almost everything.)
That's assuming that the type of input is fixed. If not, you might want to make it a generic method:
void MethodTest<T>(Predicate<T> predicate)