Call ovverided method base of base

S

smrah1

Hi

we have like below code:

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
A a = new C();
a.Write();
}
}

class A
{
public virtual void Write()
{
Console.WriteLine("Class A");
}
}

class B : A
{
public override void Write()
{
Console.WriteLine("Class B");
}
}

class C : B
{
public override void Write()
{
Console.WriteLine("Class C");
base.Write();
}
}
}

When run ,outout is:

Class C
Class B

Now I want change below line of class C:

base.Write();

that output will like :

Class C
Class A

in Other words,change overrided method of class C that no run method
of base (class B) but run this method on - class A (base of base of
class C).

thanks
SMRAH1
 
B

Brian

In class C you could probably do this (although I haven't tested):

((A)base).Write();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top