I have a method with the following overloads:
string Call(string function, Dictionary<string, object> parameters, object body)
string Call(string function, Dictionary<string, object> parameters, JObject body)
Now I added another overload:
string Call(string function)
{
return Call(function, null, (JObject) null);
}
I added a cast to JObject
so the compiler knows which overload it should use. But Visual Studio tells me that the cast is redundant. But why isn't my call ambiguous without the cast?
null
isnull
, but the cast here is a hint which overload should be used.JObject
overload even if I don't cast toJObject
because it uses the most specific overload that matches the parameters, andnull
can match anything andJObject
is more specific thanobject
. See Jon Skeet's answer for a detailed explanation.