新和覆盖之间的区别? [英] Difference between new and override?
问题描述
我有我想为所有的继承类方法的一些'基地'功能的基类
I have a base class which I want to provide some 'base' functionality for methods for all inheriting classes.
在我的继承类我想做的事:
In my inheriting classes I want to do:
public override void Setup()
{
base.Setup();
}
但此刻它说我必须使用new关键字。
But at the moment it says I have to use the new keyword.
如何到我,所以我必须使用覆盖
关键字?
How to I have it so I have to use the override
keyword?
有与当前正在使用的新
关键字,并使用覆盖
它是如何与我有什么区别?
Is there any difference between how it is currently with me using the new
keyword and using override
?
推荐答案
这是这么说的,因为你没有声明的基方法虚拟
。一旦你这样做,基虚拟
/派生覆盖
对关键字才有意义。眼下,编译器抱怨,你不能覆盖
非 - 虚拟
法
It says so because you have not declared the base method virtual
. Once you do so, the base virtual
/derived override
pair of keywords will make sense. Right now, the compiler is complaining that you cannot override
a non-virtual
method.
这篇关于新和覆盖之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!