Your overriding is just fine. Your concern is about the very hard of OOP, which you should understand well, otherwise you won't be able to proceed correctly with any kind of .NET works.
First, you need to see the difference between
compile-time types and
runtime types.
public class Mammal {
public override string ToString() { return ; }
}
public class Panda: Mammal {
public override string ToString() { return ; }
}
Panda panda = new Panda();
Mammal someMammal = new Panda();
string someString = someMammal.ToString();
The answer to the question in the above comment: the call to
ToString()
will be dispatched to
Panda.ToString()
,
despite the fact the variable type is
Mammal
.
If the method wasn't virtual, the method of the variable compile-time would be called, the one of
Mammal
. This is the whole point of OOP: virtual methods are dispatch dynamically to the ones of the actual run-time type; for non-virtual, the method according to the compile-time type is called. Virtual methods are dispatches dynamically (they are
late-bound), non-virtual — statically.
[EDIT]
See also:
http://en.wikipedia.org/wiki/Dynamic_dispatch[
^],
http://en.wikipedia.org/wiki/Virtual_method_table[
^],
http://en.wikipedia.org/wiki/Virtual_function[
^].
[EDIT]
Please see my other past answer:
http://www.codeproject.com/Answers/597424/wherepluscanplusIplusfindplusinformationplusaboutp#answer1
—SA