Inner classes in C # work differently than in Java.
In Java, the inner class has access to the outer class: during construction, each instance stores a reference to its parent, who created the instance.
In C #, inner classes are an easy way to define classes that have access to private members of an instance. In other words, when you get or save a link to mainForm , you can read / write / modify private fields and call private methods. There is no such thing as an external relation.
As a result, you can define the constructor in your inner class to the outer, and then set the parent field:
namespace Moneypoly { public partial class mainForm { public class chance { private readonly mainForm outer; public chance (mainForm outer) { this.outer = outer; } public void chanceOptionOne() { outer.discriptionPlayer1.Text = ""; } } } }
Note that you will need to give a link to mainForm when building chance : possibly using this .
This is actually what Java does (except that it is invisible to the programmer).
In addition, in C # (and Java) it is configured to start the class name (and in the case of C # methods) with an uppercase letter.
source share