Method overload resolution unexpected behavior

后端 未结 3 1016
醉话见心
醉话见心 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:21

    An Enum is just mapped to an int (by default). 0 does not map to your Enum so the overload that takes an object is used. 1 maps to your enum so the Enum overload is used.

    You could do this:

    Execute((object) 1);
    

    to output

    object overload: 1

提交回复
热议问题