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());
}
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With