如果我做,
public class test
{
public int add(int a, float b)
{
return a + Convert.ToInt32(b);
}
public int add(float a, int b)
{
return Convert.ToInt32(a) + b;
}
}
然后它编译成功,但给出后期绑定运行时错误:
The call is ambiguous between the following methods or properties
但如果我这样做
public class test
{
public int add(int a, float b)
{
return a + Convert.ToInt32(b);
}
public int add(int a, int b)
{
return Convert.ToInt32(a) + b;
}
}
然后它可以正常工作并在 test.add(1,2) 的情况下调用第二个 add 方法。它也适用于我用小数替换浮点数的情况。
我可以对上述错误有一点解释吗?