That's a simultaneously fun and annoying problem to have! :) I believe that one of the missing links here is this:
- The overridemodifier is related tovirtualorabstractmethods; a method with anoverridemodifier simply provides an alternative implementation to an existingvirtualorabstractmethod. Avirtualmethod has a default implementation, anabstractmethod has no implementation at all.
- The newmodifier however can be applied to any method and simply allows the reuse of a name that was already taken. These methods are not related to each other at all, the only similarity being that they forcibly share the same name.
The problem with new is that the type using a new method "pretends" that the original implementation never existed. The base class however is absolutely unaware of this - new severs the link in the hierarchy, and this is what's casing your problem.
Generally speaking, you do not want to use the new modifier.
That, and you probably wanted to use var m = new Program(); instead - reasons being explained below.
No comments:
Post a Comment