namespace Rextester
{
public class BaseException : Exception
{
public BaseException() { }
}
public class Program
{
public static void MethodA(BaseException e)
{
Console.WriteLine("BaseException");
}
public static void MethodA(Exception e)
{
Console.WriteLine("Exception");
}
public static void Main(string[] args)
{
try
{
throw new BaseException();
}
catch (Exception e)
{
Console.WriteLine(e.GetType());
MethodA(e);
}
}
}
}
好傢伙我根據上述執行的代碼的結果有一個問題:)C#選定重載方法在運行時
e.GetType(== Rextester.BaseException
治法寫入到控制檯:異常
因此,即使異常的類型是派生類,爲什麼在運行時沒有調用具有參數BaseException的特定重載方法,並且被稱爲帶Exception的那個?
你的問題不清楚。請添加更多描述 –
Idk此處不清楚:o – sTrenat