Can't use virtual and override on the same method in C#

后端 未结 6 1504
你的背包
你的背包 2020-12-15 04:53

So apparently you cannot use the virtual modifier with the override modifier.

virtual - a method that can be overridden

<
6条回答
  •  我在风中等你
    2020-12-15 05:37

    I think you simply misunderstood how virtual works. It's not limited to one level of inheritance, as explained here, for example:

    For every virtual method declared in or inherited by a class, there exists a most derived implementation of the method with respect to that class. The most derived implementation of a virtual method M with respect to a class R is determined as follows:
    •If R contains the introducing virtual declaration of M, then this is the most derived implementation of M.
    •Otherwise, if R contains an override of M, then this is the most derived implementation of M.
    •Otherwise, the most derived implementation of M with respect to R is the same as the most derived implementation of M with respect to the direct base class of R.

提交回复
热议问题