title: Changing instance variables from another class C#
body: <p>I have a form "Main" and a form "Prices". The Main class has a Ingredient subclass, and instances of that subclass are initialized in the Main constructor. The Main form launches the Prices form after a button is pressed. The Prices form has a few text boxes and a button.</p>
  
  <p>The problem is that I want to modify variables of instances of the Ingredient subclass by using fresh input data from the Prices form. I realize that passing those variables to the Prices form can be easily done through the constructor arguments, however, I can't figure out how to pass those modified variables back to the Main class as I'll need them there after I'll will close the Prices form.</p>
  
  <p>Main class</p>
  
  <pre><code>public partial class Main : Form
  {
      public class Ingredient
      {
          public string name;
          public  int weight;
          public  int price;
          public  int energy;
          public  int tmp;
  
          public Ingredient(string mName, int mWeight, int mPrice, int mEnergy)
          {
  
              name = mName;
              weight = mWeight;
              price = mPrice;
              energy = mEnergy;
          }
      }
  
  
      public Main()
      {
          InitializeComponent();
          Ingredient hazulnuts = new Ingredient("hazulnuts", 0, 0, 0);        
      }
  
  
      private void bEditPrices_Click(object sender, EventArgs e)
      {
          // I could pass variables of the Ingredients instance here through the constructor,
          // but haven't done so yet because I'm hoping there is some way that I can directly
          // access variables of instances of Ingredient class as there could be quite a lot 
          //of these instances
          Prices prices = new Prices();
          prices.Show();
          // The Main form is hidden when the Prices form is shown, therefore instantiating a new 
          //Main from the Prices isn't an option
          this.Hide();
      }
  
  }
  </code></pre>
  
  <p>Prices class:</p>
  
  <pre><code>public partial class Prices : Form
  {
  
      public Prices()
      {
          InitializeComponent();
  
      }
  
      private void save_Click(object sender, EventArgs e)
      {
      // retrieve values of textboxes somehow pass the variables back to the
      // Main form's Ingredient instances
  
       //I realize that the code below is not syntactically correct but I'm looking 
       //for something along of the lines of that.
          this.Close;
          Main.show();
      }
  
  
  }
  </code></pre>