That's a simultaneously fun and annoying problem to have! :) I believe that one of the missing links here is this:
- The
override
modifier is related tovirtual
orabstract
methods; a method with anoverride
modifier simply provides an alternative implementation to an existingvirtual
orabstract
method. Avirtual
method has a default implementation, anabstract
method has no implementation at all. - The
new
modifier 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