Monday, May 26, 2008

Cannot convert from 'anonymous method' to 'System.Predicate'

List<MyClass> list = // get list

outputList = list.FindAll(delegate(MyClass item)
{
if (condition)
{
return true;
}

}
);

When compiling, we get a strange error message:
"cannot convert from 'anonymous method' to 'System.Predicate'".

Only when we tried to explicitly cast the anonymous delegate to a Predicate we get a proper compiler error:
'System.Predicate': not all code paths return a value'

Hope this helps

Thanks and Regards,

Hemant