我有课
public class Overloaded
{
public void ComplexOverloadResolution(params string[] something)
{
Console.WriteLine("Normal Winner");
}
public void ComplexOverloadResolution<M>(M something)
{
Console.WriteLine("Confused");
}
}
如果我这样说:
var blah = new Overloaded();
blah.ComplexOverloadResolution("Which wins?");
它将 Normal Winner
写入控制台。
但是,如果我加上另一种方法:
public void ComplexOverloadResolution(string something, object somethingElse = null)
{
Console.WriteLine("Added Later");
}
I get the following error:
The call is ambiguous between the following methods or properties: > '
Overloaded.ComplexOverloadResolution(params string[])
' and 'Overloaded.ComplexOverloadResolution<string>(string)
'
我可以理解,添加一个方法可能会引入一个调用模糊性,但它是两个已经存在的 (params string[])
和 <string>(string)
方法之间的一个模糊性!显然,这种模糊性涉及的两个方法都不是新添加的方法,因为第一个是参数,第二个是泛型。
Is this a bug? What part of the spec says that this should be the case?