Click here to Skip to main content
15,867,756 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have

C#
class A
{
   protected virtual void OnActivate()
   {
       ...
   }
   ...
}

class B : A
{
   protected override void OnActivate()
   {
       base.OnActivate();
       ...
   }
   ...
}

class C : B
{
   protected override void OnActivate()
   {
       ????
   }
   ...
}


My question is, is it possible for class C to call class A's OnActivate without calling class B's method? If so, how?

Thanks

Brent

What I have tried:

Duplicating class A's code in class C.
Posted
Updated 17-Mar-16 6:46am

1 solution

No, it's not possible in the way you want it and that's for a good reason: You would violate one of the OOP-principles: Polymorphism (computer science) - Wikipedia[^]

A great answer to exactly the same question on StackOverflow from Eric Lippert, one of the C# language designers: c# - How to call base.base.method()? - Stack Overflow[^]

PS: If you think you need this your class design is flawed and you should rework it instead of trying to muddle through it somehow.
 
Share this answer
 
v2
Comments
dbrenth 17-Mar-16 13:29pm    
Thanks, I was simply hoping that wasn't the answer. But I understand why.
Sascha Lefèvre 17-Mar-16 13:32pm    
;-)
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900