how to implement inner outer classes in c#
i have two nested classes
like
class Outer
{
int TestVariable = 0;
class Inner
{
You can create an instance of inner class without even have outer class instance, what should happen in that case you think? That's why you can't use it
Outer.Inner iner = new Outer.Inner(); // what will be InnerTestVariable value in this case? There is no instance of Outer class, and TestVariable can exist only in instance of Outer
Here is one of the ways to do it
class Outer
{
internal int TestVariable=0;
internal class Inner
{
public Inner(int testVariable)
{
InnerTestVariable = testVariable;
}
int InnerTestVariable; //Need to access the variabe "TestVariable" here
}
internal Inner CreateInner()
{
return new Inner(TestVariable);
}
}