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