Quantcast
Viewing all articles
Browse latest Browse all 4

Answer by Mike G for Add onto method in parent class from inherited class

I see two problems here, one in your code sample and one in your understanding of how overriding works.

  • Start() is already defined as a protected virtual method of the parent class. Your definition in the derived class with conflict with the parent's definition unless you declare Start() in your derived class as protected override.
  • Declaring an override of a method does not preclude you from including the functionality provided by the base class's method. You can invoke the base class's definition of Start() by calling it using base.Start(); Your attempt to call it via MyBase.Start() doesn't work because that syntax is attempting to tell the compiler to find a static method in MyBase called Start(), which does not exist (or at least does not in the sample you've provided.)

In short, declaring Start() as protected override void and calling the base class's version via base.Start(); will accomplish your stated goal.


Viewing all articles
Browse latest Browse all 4

Trending Articles