当参数为null时如何解决歧义? [英] How to resolve ambiguity when argument is null?

查看:57
本文介绍了当参数为null时如何解决歧义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编译以下代码将返回以下方法或属性之间的调用不明确错误.由于无法将 null 显式转换为这些类中的任何一个,该如何解决呢?

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)
{

}

推荐答案

Func((Class1)null);

这篇关于当参数为null时如何解决歧义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆