c# - Force method to call base method from base class -


if creating method "override" property, derived method not call base method implementation automatically , need call manually using "base" keyword this:

public class {     public virtual void say()     {         console.write("a");     } }  public class b : {     public override void say()     {         base.say();         console.write("b");     } } 

so in case string "a" , "b" written console. question how can rid of "base.say();" line? want force every derived method "say" call base method base class. possible? looking solutions, if forced use other keywords

although not possible achieve directly, same effect writing own method not virtual, calls virtual after performing fixed operation:

public class {     public void say()     {         console.write("a");         sayimpl();     }     protected virtual void sayimpl()     {         // not write here:         // base class writing done in say()     } }  public class b : {     protected override void sayimpl()     {         console.write("b");     } } 

now class inheriting a , implementing sayimpl() have a prepended printout.


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -