How to resolve ambiguity when argument is null?

2019-02-16 07:43发布

Compiling the following code will return The call is ambiguous between the following methods or properties error. How to resolve it since I can't explicitly convert null to any of those classes?

static void Main(string[] args)
{
    Func(null);
}

void Func(Class1 a)
{

}

void Func(Class2 b)
{

}

7条回答
迷人小祖宗
2楼-- · 2019-02-16 08:04

Using as for the casting makes it slightly more readable with the same functionality.

Func(null as Class1);
查看更多
登录 后发表回答