calling a super class method from a derived class
-
Dear All, i have a class A. Class B derives class A and class C derives from class B and class D derives from class c. Now i need to call a method of class A from class D. is it possible? if so how can i acheive this. Is there any facility in C# that helps me to call the methods any of the classes A, B, C from class D? very urgent Thanks in advance
Ramesh.Kanjinghat
-
Dear All, i have a class A. Class B derives class A and class C derives from class B and class D derives from class c. Now i need to call a method of class A from class D. is it possible? if so how can i acheive this. Is there any facility in C# that helps me to call the methods any of the classes A, B, C from class D? very urgent Thanks in advance
Ramesh.Kanjinghat
Have you heard About Inheritance. this will help you. Inheritance[^]
Regards, Satips.:rose:
-
Have you heard About Inheritance. this will help you. Inheritance[^]
Regards, Satips.:rose:
Dear Satips, I know very well what inheritance is. Here my problem class A has a method Method1 and Class B inherits class A and Class C inherits class B where Class C overides the Method1 and class D inherits class C. know when i call Methodi from class D the Method1 of class C will be called. but i want to call the Method1 of class A. We can use super keyword in C++. is there any thing in C# that helps us to acheive this? got this time you got it? thanks in advance
Ramesh.Kanjinghat
-
Dear Satips, I know very well what inheritance is. Here my problem class A has a method Method1 and Class B inherits class A and Class C inherits class B where Class C overides the Method1 and class D inherits class C. know when i call Methodi from class D the Method1 of class C will be called. but i want to call the Method1 of class A. We can use super keyword in C++. is there any thing in C# that helps us to acheive this? got this time you got it? thanks in advance
Ramesh.Kanjinghat
Hello, I think you have to do a little trick here. In class C you need a additional method, which calls the base.Method (method from class A).
public override void MethodFromA() { //Class C stuff } public void BaseMethodFromA() { base.MethodFromA(); }
In class D you have to override the base method again and call the additional method in class C.
public override void MethodFromA() { BaseMethodFromA(); }
Maybe there is some cleaner solution, which I'm not aware of, but I think it will work! All the best, Martin
-
Dear All, i have a class A. Class B derives class A and class C derives from class B and class D derives from class c. Now i need to call a method of class A from class D. is it possible? if so how can i acheive this. Is there any facility in C# that helps me to call the methods any of the classes A, B, C from class D? very urgent Thanks in advance
Ramesh.Kanjinghat
No, not once the method has been hidden (with
override
ornew
). -
Hello, I think you have to do a little trick here. In class C you need a additional method, which calls the base.Method (method from class A).
public override void MethodFromA() { //Class C stuff } public void BaseMethodFromA() { base.MethodFromA(); }
In class D you have to override the base method again and call the additional method in class C.
public override void MethodFromA() { BaseMethodFromA(); }
Maybe there is some cleaner solution, which I'm not aware of, but I think it will work! All the best, Martin
Thanks
Ramesh.Kanjinghat
-
Thanks
Ramesh.Kanjinghat