疑问
到底会call哪个Test method呢?欢迎讲出原因!class Program
{
static void Main(string[] args)
{
DerivedClass dc = new DerivedClass();
int i = 5;
dc.Test(i);
((BaseClass)dc).Test(i);
Console.ReadLine();
}
}
public class BaseClass
{
public virtual void Test(int i)
{
Console.WriteLine("BaseClass.Test(int i)");
}
}
public class DerivedClass : BaseClass
{
public override void Test(int i)
{
Console.WriteLine("DerivedClass.Test(int i)");
}
public void Test(double i)
{
Console.WriteLine("DerivedClass.Test(double i)");
}
}