class A {
public virtual void Foo()
{ // do something
}
}
class B:A {
public void Foo() {
}
}
What’s the meaning of this? Can anyone give me an example? Up till now i thought that it’s mandatory to use the “override” keyword if you use virtual
Thanks
If you use such declaration you will just “hide” the
Foomethod of theAclass using instance of theBclass. When you cast this instance to theAand callFoothe method ofAclass will be called.If you will use
overridein the classByou will useFoomethod of theBclass if you create instance of theBand then cast toA.With override:
For details you can Google a little. For example this post: Polymorphism, Method Hiding and Overriding in C#