C # Resolution overload method
I have the following methods:
static void OverloadedMethod(Action<ulong> handlerAction)
{
}
static void OverloadedMethod(Action<float> handlerAction)
{
}
static void HandlerA(ulong dataProgress)
{
}
static void HandlerB(float dataProgress)
{
}
I can call
OverloadedMethod(HandlerA);
no problem, but if i try to call
OverloadedMethod(HandlerB);
The compiler complains: Ambiguous call.
I read this article , but I don't understand why the compiler knows which method to choose if the parameter is ulong, but it cannot solve the same situation if the parameter is a float ...
+3
Nomada
source
to share
2 answers
According to MSDN , there is a predefined implicit conversion from ulong to float. As a result, the implicit conversion prevents the compiler from knowing which method to call.
+1
David L
source
to share
Take a look at covariance and contravariance here
-2
Guillermo ruffino
source
to share