c# - Inheritance and Overriding Methods/Properties -
If I have two squares, which gets from the other and I use the same method / property name in both
Public class MyBase:
{Public Ink GetNumber () {Return 1; }} Public Sector MyDerived: MyBase {Public New Inc GetNumber () {Return 20; }} Myvard Avver = new Mirdiwide (); Int derivedVar = someVar.GetNumber (); // 20 mibbase baseware = (mybase) somewhere; Int baseVar = baseVar.GetNumber (); // 1
My tendency would be to use override instead of new for derived class, but I get "no member found to override".
"post-text" itemprop = "text">
You must mark override
before virtual
Is required.
Public Square MySubses {Public Virtual Ink GetNumber () {Return 1; }} Public class MyDerived: MyBase {public override int Gatenumber () {returns 20; }}
Comments
Post a Comment