【发布时间】:2014-06-02 11:28:33
【问题描述】:
好的,我有一个派生类,它对我的基类上的方法有重载。我称我认为与基类的方法签名匹配,而是调用我的派生类实现。 (下面的代码总是打印出“MyDerived”)这是为什么?
public class MyBase
{
public void DoSomething(int a)
{
Console.WriteLine("MyBase");
}
}
public class MyDerived : MyBase
{
public void DoSomething(long a)
{
Console.WriteLine("MyDerived");
}
}
Main()
{
MyDerived d = new MyDerived();
d.DoSomething((int)5);
}
【问题讨论】:
-
对不起!我的意思是它会打印出 MyDerived!错字我现在改!
标签: c# asp.net inheritance polymorphism