什么是虚拟方法? [英] What are Virtual Methods?
本文介绍了什么是虚拟方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你为什么要声明一个方法是虚拟。
Why would you declare a method as "virtual".
什么是使用虚拟受益?
推荐答案
修改被用于标记的方法\\属性(ECT)可以在派生类中使用的覆盖修改。
The Virtual Modifier is used to mark that a method\property(ect) can be modified in a derived class by using the override modifier.
例如:
class A
{
public virtual void Foo()
//DoStuff For A
}
class B : A
{
public override void Foo()
//DoStuff For B
//now call the base to do the stuff for A and B
//if required
base.Foo()
}
这篇关于什么是虚拟方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文