Method overload resolution unexpected behavior

后端 未结 3 1009
醉话见心
醉话见心 2020-12-02 01:55

I\'m wrestling with a weird, at least for me, method overloading resolution of .net. I\'ve written a small sample to reproduce the issue:

class Program
{
            


        
3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-02 02:03

    I agree with Jon Skeet's answer - refer to his post (above) on Jan 11 at 17:32. To expand further, please refer to C# language specification - page: 110

    6.1.3 Implicit enumeration conversions An implicit enumeration conversion permits the decimal-integer-literal 0 to be converted to any enum-type and to any nullable-type whose underlying type is an enum-type. In the latter case the conversion is evaluated by converting to the underlying enum-type and wrapping the result (§4.1.10).

    Still there is a problem:

    adding the statement:

    test.Execute(-0.0); //object overload: 0

    while adding the following:

    test.Execute(+0.0); //enum overload: 0

    Jacques Colmenero Enterprise Architect colmeneroj@videotron.ca

提交回复
热议问题