Reputation: 7484
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());
}
Upvotes: 12
Views: 4070
Reputation: 727067
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);
}
Upvotes: 18