Is there a smart way to access any attribute/function of outer class from the inner class? This is a very intelligent property of Java , I don't know whether C# offer such a way that is similar with Java or not. Any idea? i wrapped a Java example below. Thanks...
(*) I know that the straightforward solution is to use home-pattern like defining
But, I don't want to use home pattern!... Here is the Java-way:Code:class Inner { Inner( Outer home ); // get it from constructor }
Code:public class Outer { class Inner { int innerMember; void DoSomething() { innerMember = Outer.this.outerMember; } } public int outerMember = 1; public void Go() { Inner inner = new Inner(); inner.DoSomething(); } public static void main( String[] args ) { Outer outer = new Outer(); outer.Go(); } }




Reply With Quote