我想知道我在这里失踪了什么.在调试时我将e视为SpecificException的一个实例,但是方法调用与具有基本Exception的签名匹配.怎么会?我可以在不添加LogException方法中的类型检查的情况下解决这个问题吗?
public string LogException<T>(T e)
where T : Exception
{
string errorMsg = e.ToString();
errorMsg += Details(e);
return errorMsg;
}
public string Details(Exception exception)
{
return "foo";
}
public string Details(SpecificException exception)
{
return "bar";
}
Run Code Online (Sandbox Code Playgroud)