新建和覆盖的区别 - Difference between new and override

问题:

Wondering what the difference is between the following:想知道以下之间有什么区别:

Case 1: Base Class案例 1:基类

public void DoIt();

Case 1: Inherited class案例一:继承类

public new void DoIt();

Case 2: Base Class案例 2:基类

public virtual void DoIt();

Case 2: Inherited class案例二:继承类

public override void DoIt();

Both case 1 and 2 appear to have the same effect based on the tests I have run.根据我运行的测试,案例 1 和案例 2 似乎具有相同的效果。 Is there a difference, or a preferred way?有什么区别,还是首选方式?


解决方案:

参考一: https://stackoom.com/question/5ryZ
参考二: Difference between new and override
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章