zil*_*ong 6 c# generics overloading
我想使用方法重载来根据不同的泛型类型获得不同的结果.这是行不通的.我的代码清楚地表明了
static class Helper
{
public static bool Can(int i)
{
return true;
}
public static bool Can(Object o)
{
return false;
}
}
class My<T>
{
public static bool can = Helper.Can(default(T));
}
Console.WriteLine(Helper.Can(default(int)));//True,it is OK
Console.WriteLine(My<int>.can);//false?? why the overload doesn't work
Console.WriteLine(My<Object>.can);//false
Run Code Online (Sandbox Code Playgroud)
为什么My<int>调用Helper.Can(Object o)而不是Helper.Can(int i)?