I have two forms (Form1 and Form2). In Form1, there is a variable public public i, which is set to 1 in the constructor of Form1. Then I open Form2 from Form1 with this code:
Form2 f2 = new Form2(ref i);
f2.ShowDialog();
The constructor of form 2 looks like this:
public int i;
public Form2(ref int x)
{
InitializeComponent();
i = x;
}
Then I set the variable I in Form2 to 2 and close Form2. Now I would expect the variable I in Form1 to have a value of 2 (due to the ref keyword, passing parameters), but the value is still 1. What am I doing wrong and why does the ref keyword not work in my example?
thanks
source
share