为什么要虚拟的方法在C#中明确覆盖?明确、方法

2023-09-03 06:09:55 作者:◎画地为牢ヽ

为什么要虚拟方法来明确在C#中重写?

Why should virtual methods be explicitly overridden in C#?

推荐答案

通过声明一个方法虚拟,您的,说明你的意图的是该方法可以在派生类中重写。

By declaring a method as virtual, you are stating your intention that the method can be overridden in a derived class.

通过声明的实施方法,覆盖,你是,说明你的意图的情况:要覆盖一个虚拟方法。

By declaring your implementing method as override, your are stating your intention that you are overriding a virtual method.

通过要求覆盖关键字可以用来覆盖一个虚方法,语言的设计者鼓励清晰,通过要求你说明你的意图。

By requiring that the override keyword be used to override a virtual method, the designers of the language encourage clarity, by requiring you to state your intentions.