为什么要将方法声明为“虚拟”。
使用虚拟有什么好处?
最佳答案
Virtual修饰符用于标记可以在派生类中使用 override 修改方法\属性(等)修饰符。
例子:
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()
}
关于c# - 什么是虚拟方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/622132/