WHy should virtual methods be explicitly overridden in C#?

前端 未结 5 1708
遇见更好的自我
遇见更好的自我 2021-02-20 02:08

Why should virtual methods be explicitly overridden in C#?

5条回答
  •  时光取名叫无心
    2021-02-20 02:15

    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.

提交回复
热议问题