当参数为null时如何解决歧义? [英] How to resolve ambiguity when argument is null?
本文介绍了当参数为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屋!
查看全文