Why is this cast redundant?
Solution 1:
But why isn't my call ambiguous without the cast?
Because the overload with the JObject
parameter is "better" than the overload with the object
parameter... because the conversion from null
to JObject
is "better" than the conversion from null
to object
.
JObject
is more specific than object
, because there's an implicit conversion from JObject
to object
, but not vice versa.
If the final parameter for the first method were string
instead (for example) then neither overload would be better than the other, and the call would be ambiguous without the cast.
See section 7.5.3 of the C# 5 specification for all the intricate details. In particular, section 7.5.3.5 ("better conversion target") is relevant here.