Calling a base method using a new keyword

in this link , they have this code:

public class Base { public virtual void Method(){} } public class Derived : Base { public new void Method(){} } 

and then called like this:

 Base b = new Derived(); b.Method(); 

my actual code is:

 public class Base { public void Method() { // bla bla bla } } public class Derived : Base { public new void Method() { base.Method(); } } 

need to call using base.Method(); ?
or just leave the method in the derived class empty?

+6
source share
1 answer

you need a "base" if you really need to call a base class method. base.Method(); - the right way.

Know when to use redefinition and new keywords (C # Programming Guide)

+6
source

Source: https://habr.com/ru/post/915251/


All Articles