Link to home
Start Free TrialLog in
Avatar of chsalvia
chsalvia

asked on

Get Reference to Parent Class

If you have a nested class inside a parent class, the 'this' keyword will of course refer to an instance of the nested class when used inside the nested class.  But is there any way to get a reference to an instance of the parent class, without passing one over to the constructor of the nested class?  
public class Parent
{
    class Nested
    {
        void doSomething()
        {
            Parent p = this; // <--- doesn't work because 'this' refers to an instance of Nested
        }
    }          
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial