Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I resolve this ambiguous call error

I get the following error at compile time. How do I resolve it without having to resort to different function names

private double SomeMethodName(SomeClassType value)
{           
    return 0.0;
}
private double SomeMethodName(ADifferentClassType value)
{
    if (value == null)
    {
        return this.SomeMethodName(null);  //<- error
    }
    return this.SomeMethodName(new SomeClassType());  
}
like image 743
Eminem Avatar asked May 26 '13 00:05

Eminem


1 Answers

The compiler is confused, because null matches both overloads. You can explicitly cast null to the class that you need to let the compiler know which of the two overloads you are calling:

if (value == null)
{
    return this.SomeMethodName((SomeClassType)null);
}
like image 195
Sergey Kalinichenko Avatar answered Oct 16 '22 11:10

Sergey Kalinichenko