If I have two classes, one which inherits from the other and I use the same method/property name in both, how can I make that method call the subclass regardless of whether the current object has been cast back to it's base class.
For example (extraneous parts omitted):
public class MyBase {
public int GetNumber() {
return 1;
}
}
public class MyDerived : MyBase {
public new int GetNumber() {
return 20;
}
}
MyDervied someVar = new MyDerived();
int derivedVar = someVar.GetNumber(); // 20
MyBase baseVar = (MyBase)someVar;
int baseVar = baseVar.GetNumber(); // 1
My instinct would be to use override instead of new for the derived class, but I get a "no member found to override".