下面的代码抛出 “不明确的调用匹配” 在编译时:暧昧调用匹配混乱
class ABC{}
class DEF{}
class Program
{
static void Main(string[] args)
{
Debug.WriteLine(func(null));
}
static string func(ABC abc)
{
return "";
}
static string func(DEF def)
{
return "";
}
}
但是,下面的代码编译并运行正常:
static void Main(string[] args)
{
Debug.WriteLine(func(null));
}
static string func(int? abc)
{
return "function a";
}
static string func(float? def)
{
return "function b";
}
1.4.3
function a
C#如何知道在第二个示例中选择哪个函数?
' 浮子F = 1; //工作 INT I = 1.0F; //不工作 ' 确定有意义 – Isaac
奈斯利说明。 –