10

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 this:

public class Base
{
   public void Method()
   {
        // bla bla bla
   }
}

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

is it necessary to call with base.Method(); ?
or just leave the method in derived class blank ?

Community
  • 1
  • 1
asakura89
  • 531
  • 1
  • 12
  • 20
  • Good question. This tends to get missed in most of the online helps regarding derivations. – MrWuf May 09 '12 at 03:03

1 Answers1

7

you need 'base' if you really need to call the base class's method. base.Method(); is the correct way.

Knowing When to Use Override and New Keywords (C# Programming Guide)

Arve Systad
  • 5,471
  • 1
  • 32
  • 58
ABCD
  • 897
  • 16
  • 38
  • 1
    Old link. Report a summary please: https://learn.microsoft.com/en-US/dotnet/csharp/programming-guide/classes-and-structs/knowing-when-to-use-override-and-new-keywords – Emanuele Nov 22 '17 at 15:17