Reputation: 531
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 ?
Upvotes: 10
Views: 6023
Reputation: 907
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)
Upvotes: 7