Java inner classes in c#

c#, inner-classes, java

Solution

You need to make the inner class take an instance of the outer class as a constructor parameter. (This is how the Java compiler implements inner classes)

Problem

I have the following Java code: ``` public class A { private int var_a = 666; public A() { B b = new B(); b.method123(); System.out.println(b.var_b); } public class B { private int var_b = 999; public void method123() { System.out.println(A.this.var_a); } } } ``` Which yields 666 and 999. Now, I've tried to set up similar code in c#, but it seems that it is not possible to accomplish the same. If that's the case, how you usually achieve a similar effect when programming in c#?

Original source