Inner class and Outer class in c#

c#

Solution

No, C# does not have the same semantics as Java in this case. You can either make `TestVariable` `const`, `static`, or pass an instance of `Outer` to the constructor of `Inner` as you already noted.

Problem

how to implement inner outer classes in c# i have two nested classes like ``` class Outer { int TestVariable = 0; class Inner { int InnerTestVariable = TestVariable // Need to access the variable "TestVariable" here } } ``` Its showing error while compiling. It can be solved by 1) Making TestVariable as static 2) Passing an instance of Outer class to Inner class but in java there is no need to create Instance or static . can i use the same functionality in C# too ?

Original source