假设有这样一个类。
public class SomeClass<T>
{
public void DoSomething(int x)
{
Console.WriteLine("DoSomething(int x) called");
}
public void DoSomething(T x)
{
Console.WriteLine("DoSomething(T x) called");
}
}
还有一段代码
var someObj = new SomeClass<int>();
我有两个问题。
1) 私有类型SomeClass<int>有两个具有相同签名的方法。那为什么编译器不骂他们呢?
2)说如果打电话
someObj.DoSomething(0);
这段代码写着“DoSomething(int x) called”。为什么使用整数参数而不是通用参数调用变体?