0

how do i extend a behaviour from the base class like this?

public class A  {
    protected virtual void foo () {
        Console.WriteLine("hi")
    }
}

public class B : A  {
    protected override void foo () {
        Console.WriteLine("hihi")
    }
}

a = new A();
a.foo() 

-> "hi"
-> "hihi"

When calling foo in the parent class i want to execute a behavior specific for that class while at the same time calling it in the child. Is it possible to do this with just accessing the parent?

binbin
  • 25
  • 1
  • 6

1 Answers1

3

You need to use the base keyword

base.myParentMethod();

Use that inside the overriden method if you want both actions to be performed.

phadaphunk
  • 12,785
  • 15
  • 73
  • 107