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

后端 未结 6 1503
你的背包
你的背包 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:48

    virtual means your method is dispatched through a virtual method table. If a method's virtual, any reference to that method on a derived class has to go through the vtable. You can't non-virtualize it just because a derived class overrides it - what would happen if LittleLine was cast to DrawingObject? You still need to find the correct implementation, which wouldn't be DrawingObject's

提交回复
热议问题