新建和覆蓋的區別 - 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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章