Ambiguous method overloading

前端 未结 2 1803
时光取名叫无心
时光取名叫无心 2020-12-11 05:12

This issue has caught me out once again. Could someone provide a technical explanation as to why the following code does not produce any warnings or errors. The question you

2条回答
  •  醉酒成梦
    2020-12-11 05:26

    The simple answer is that it doesn't give any errors or warnings because it's entirely valid code by the C# spec.

    The relevant section of the C# 4 spec is 7.5.3 in general (for the whole process), and 7.5.3.2 to determine which applicable function member is better when the first phase has found more than one. (The subsequent sections such as 7.5.3.5 give details about "better conversion targets" etc.)

    Trying to explain the rules absolutely correctly but in a short space would be hard to say the least, unfortunately. I suggest you look through that bit of the spec yourself very carefully.

提交回复
热议问题