title: Updating a global variable in C#
body: <p>I have a variable that I am gong to access from this bit of code. The variable is: balance<br>
  This is a snippet of the code from Form3:</p>
  
  <pre><code>    public static int balance = 0;
      private void button1_Click(object sender, EventArgs e)
      {
         int deposit=int.Parse(textBox1.Text);
         if (deposit == 0)
         {
             MessageBox.Show("Please enter a value greater than 0");
         }
         else
         {
  
             balance = balance + deposit;
             MessageBox.Show("Thank you, your balance has been updated.");
         }
      }
  </code></pre>
  
  <p>Now when I want to deposit money, I want the balance to update so that when I view it from another form it needs to be the edited balance (the balance updated with the amount they deposit). I am struggling to get the balance to update, it works when I am in the Form that updates but then when I go to view it in another Form it still shows the balance as 0.</p>
  
  <pre><code>int bal = Form3.balance;
      public int Balance()
      {
          //MessageBox.Show("Your current balance is: "+bal);
          return bal;
      }
      private void button1_Click(object sender, EventArgs e)
      {
         /*if (bal &lt; 0)
          {
              MessageBox.Show("You don't have enough cash in your account, please deposit some money before you can continue");
          }
          else*/ 
          if (bal &lt; 5)
          {
              MessageBox.Show("Please credit your account before you can withdraw");
          }
          else
          {
              MessageBox.Show("Please wait for your £5 to be dispensed");
              bal = bal - 5;
  
              Balance();//I thought if I returned the balance variable from a different method that it would still update regardless
              //I am struggling making sure that the balance gets updated.
          }
  
      }
  </code></pre>
  
  <p>What do I do to ensure that my balance variable is updated globally??</p>