|
ms
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Inheritance - Accessing two levels above mineHow can I access a (non-static) member method that is two levels above mine, from a member method that has the same name? How can I access C_A0.func() from inside C_A000.func() ??? Is this possible? Thanks a lot. Bill // ---------------------------- namespace Project0 { public class C_A0 { public int func() { return(1); } } public class C_A00 : C_A0 { new public int func() { return(2); } } public class C_A000 : C_A00 { new public int func() { // How can I access C_A0.func() from here?? // It does not let me write "base.base.func()". I can access the first "base", but not the second one. // It does not let me write "C_A0.func()", because that function is not static. return(3); } } }
Show quote
Hide quote
"Bill" <a@a.a> wrote in message winthin class C_A000.func() you can do this:news:v5tlk4hqcon1qbkttui83tumbk1rn6gsij@4ax.com... > Hi, > > How can I access a (non-static) member method that is two levels above > mine, from a member method that has the same name? > > How can I access C_A0.func() from inside C_A000.func() ??? > > Is this possible? > > Thanks a lot. > Bill > > > // ---------------------------- > namespace Project0 > { > public class C_A0 > { > public int func() > { > return(1); > } > } > > public class C_A00 : C_A0 > { > new public int func() > { > return(2); > } > } > > public class C_A000 : C_A00 > { > new public int func() > { > // How can I access C_A0.func() from here?? > // It does not let me write "base.base.func()". I can access the > first "base", but not the second one. > // It does not let me write "C_A0.func()", because that function > is not static. > return(3); > } > } > } > ( (C_A0) ((C_A00) this) ).func() -- Mike
Show quote
Hide quote
"Family Tree Mike" <F**@ThisOldHouse.com> wrote in message That was dumb... Just do this:news:EE42C9E5-5A3C-4636-8587-71B951F744D8@microsoft.com... > "Bill" <a@a.a> wrote in message > news:v5tlk4hqcon1qbkttui83tumbk1rn6gsij@4ax.com... >> Hi, >> >> How can I access a (non-static) member method that is two levels above >> mine, from a member method that has the same name? >> >> How can I access C_A0.func() from inside C_A000.func() ??? >> >> Is this possible? >> >> Thanks a lot. >> Bill >> >> >> // ---------------------------- >> namespace Project0 >> { >> public class C_A0 >> { >> public int func() >> { >> return(1); >> } >> } >> >> public class C_A00 : C_A0 >> { >> new public int func() >> { >> return(2); >> } >> } >> >> public class C_A000 : C_A00 >> { >> new public int func() >> { >> // How can I access C_A0.func() from here?? >> // It does not let me write "base.base.func()". I can access the >> first "base", but not the second one. >> // It does not let me write "C_A0.func()", because that function >> is not static. >> return(3); >> } >> } >> } >> > > > winthin class C_A000.func() you can do this: > > ( (C_A0) ((C_A00) this) ).func() > > -- > Mike > ((C_A0) this).func(); -- Mike As Mike said you can just type cast "this" to the base class. Note though
that if the method is virtual and overridden this wont work, and trying to execute a specific base class's implementation of a virtual method (other than your direct ancestor class) is a sign of a bad design.
Other interesting topics
Search all nodes using Linq
installer class failure Dynamically using object methods Transition from C# to VB.NET XML => Object stored in memory? xml Second message loop a Windows Forms application? Filtering a XmlNodeList delegate parameter - can I do this? How to stop Invoked code running immediately after ShowDialog() closes |
|||||||||||||||||||||||