Assuming the following delegate "caller" signature:
FuncCaller<T>(Func<T, bool> predicate)
and a matching method:
bool MyFunc(object o)
When T
is a reference type, I can invoke MyFunc
implicitly like so:
FuncCaller<String>(MyFunc) // valid
Conversely, when T
is a value type, I get a compilation error when calling MyFunc implicitly:
FuncCaller<Int32>(MyFunc) // invalid ("No overload for 'MyFunc(object)' matches delegate 'System.Func<int?,bool>'")
My question is, given these two examples, why is the call to MyFunc
invalid when invoked implicitly, but valid when invoked explicitly like so:
FuncCaller<Int32>(i => MyFunc(i)) // valid
I assume this is some kind of issue related to boxing and unboxing of types?