How to have a default method while still be able to override it?
This question already has an answer here:
You need to declare the base virtual
(which means it can be overridden if necessary) and override
it where you need different behavior from the original. The non-overridden derived class will behave just like the base class.
public class Parent()
{
public virtual DataTable FetchScore()
{
// blahblah
}
}
public class ChildNormal() : Parent
{
}
public class ChildOdd() : Parent
{
public override DataTable FetchScore()
{
DataTable dt = base.FetchScore();
// blahblah
}
}
链接地址: http://www.djcxy.com/p/38116.html
上一篇: 在c#中实际使用虚函数
下一篇: 如何有一个默认的方法,但仍然能够覆盖它?