Method overloads resolution and Jon Skeet's Brain Teasers

前端 未结 5 1542
無奈伤痛
無奈伤痛 2020-12-13 06:45

Jon\'s Brain Teasers

Here Be Spoilers...

I\'m looking at the answer to #1, and I must admit I never knew this was the case in overload resol

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-13 07:37

    The reason is because it is ambiguous. The compiler just has to decide for one. And somebody thought that the less indirect one would be better (performance might be a reason). If the developer just wrote:

    ((Base)d).Foo (i);
    

    it's clear and giving you the expected result.

提交回复
热议问题