title: Pass parameter by reference between two Forms
body: <p>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:</p>
  
  <pre><code>Form2 f2 = new Form2(ref i);
  f2.ShowDialog();
  </code></pre>
  
  <p>The constructor of Form2 looks like this:</p>
  
  <pre><code>public int i;
  public Form2(ref int x)
  {
      InitializeComponent();
      i = x;
  }
  </code></pre>
  
  <p>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?</p>
  
  <p>Thanks</p>