do math operations with variables from a list
<p>i need to take a list read from a binary file and multiply several of the varible in the list.</p>

<p>Example : VariableA = list1*300 + list2*130 + list3*80</p>

<p>Then i have to take VariableA and put it into a list to write to a separate file</p>

<p>i am not sure how to write the code for this, if i need VariableA to be declared global or what?</p>

<p>Warning : yes i am new to C# this may be a newb question but its one that i cant seem to find the answer to online</p>

<p>current code : </p>

<pre><code> using System;
 using System.Collections.Generic;
 using System.ComponentModel;
 using System.Data;
 using System.Drawing;
 using System.Linq;
 using System.Text;
 using System.Windows.Forms;
 using System.IO;
 using System.Runtime.Serialization.Formatters.Binary;

namespace test
{

public partial class Form1 : Form
{
    [Serializable]
    public class ore
    {
        public float Cost;

    }
        [Serializable]
    public class comodity
{

            public float comodityCost;

}



    private List&lt;ore&gt; oreData = new List&lt;ore&gt;();
    private ore b1 = null;
    private ore b2 = null;
    private ore b3 = null;
    private ore b4 = null;
    private ore b5 = null;
    private ore b6 = null;
    private ore b7 = null;
    private ore b8 = null;
    private ore b9 = null;


    private List&lt;comodity&gt; comodityData = new List&lt;comodity&gt;();
    private comodity o1 = null;
    private comodity o2 = null;
    private comodity o3 = null;
    private comodity o4 = null;
    private comodity o5 = null;
    private comodity o6 = null;
    private comodity o7 = null;
    private comodity o8 = null;
    private comodity o9 = null;
    private comodity o10 = null;
    private comodity o11 = null;
    private comodity o12 = null;
    private comodity o13 = null;
    private comodity o14 = null;
    private comodity o15 = null;


    public Form1()
    {
        InitializeComponent();
       b1 = new ore();
       b2 = new ore();
       b3 = new ore();
       b4 = new ore();
       b5 = new ore();
       b6 = new ore();
       b7 = new ore();
       b8 = new ore();
       b9 = new ore();
        oreData.Add (b1);
        oreData.Add(b2);
        oreData.Add(b3);
        oreData.Add(b4);
        oreData.Add(b5);
        oreData.Add(b6);
        oreData.Add(b7);
        oreData.Add(b8);
        oreData.Add(b9);


        o1 = new comodity();
        o2 = new comodity();
        o3 = new comodity();
        o4 = new comodity();
        o5 = new comodity();
        o6 = new comodity();
        o7 = new comodity();
        o8 = new comodity();
        o9 = new comodity();
        o10 = new comodity();
        o11 = new comodity();
        o12 = new comodity();
        o13 = new comodity();
        o14 = new comodity();
        o15 = new comodity();

        comodityData.Add(o1);
        comodityData.Add(o2);
        comodityData.Add(o3);
        comodityData.Add(o4);
        comodityData.Add(o5);
        comodityData.Add(o6);
        comodityData.Add(o7);
        comodityData.Add(o8);
        comodityData.Add(o9);
        comodityData.Add(o11);
        comodityData.Add(o12);
        comodityData.Add(o13);
        comodityData.Add(o14);
        comodityData.Add(o15);


    }

    private void textBox1_TextChanged(object sender, EventArgs e) //helioptris
    {
        // 1st text box input is float
        float tempFloat;


        if (float.TryParse(textBox1.Text, out tempFloat))
        {
            oreData[0].Cost = tempFloat;
        }
        else
            MessageBox.Show("uh oh");



    }


    private void textBox2_TextChanged(object sender, EventArgs e) // noralgis
    {
        // 2nd text box input is float
        float tempFloat;
        if (float.TryParse(textBox2.Text, out tempFloat))
        {
            oreData[1].Cost = tempFloat;
        }
        else
            MessageBox.Show("uh oh");


    }


    private void button1_Click(object sender, EventArgs e) // the save button
    {



        FileStream fs = new FileStream("ore.dat", FileMode.Create);
        BinaryFormatter bf = new BinaryFormatter();
        bf.Serialize(fs, oreData);
        fs.Close();
    }











    private void textBox3_TextChanged(object sender, EventArgs e)
    {
        // 3rd text box 
    }

    private void textBox4_TextChanged(object sender, EventArgs e)
    {
        //4th text box
    }


    private void button2_Click(object sender, EventArgs e)
    {
        FileStream fs = new FileStream("ore.dat", FileMode.Open);
        BinaryFormatter bf = new BinaryFormatter();
        oreData = (List&lt;ore&gt;)bf.Deserialize(fs);
        fs.Close();

        if (oreData!=null)
        {
            if (oreData.Count &gt; 0)
                textBox3.Text = oreData[0].Cost.ToString();//update the  text box helioptris
            if (oreData.Count &gt; 1)
                textBox4.Text = oreData[1].Cost.ToString();//update the  text box noralgis
            if (oreData.Count &gt; 2)
                textBox12.Text = oreData[2].Cost.ToString();//update the  text box triandulis
            if (oreData.Count &gt; 3)
                textBox13.Text = oreData[3].Cost.ToString();//update the  text box eperton
            if (oreData.Count &gt; 4)
                textBox14.Text = oreData[4].Cost.ToString();//update the  text box imentium
            if (oreData.Count &gt; 5)
                textBox15.Text = oreData[5].Cost.ToString();//update the  text box stermoit
            if (oreData.Count &gt; 6)
                textBox16.Text = oreData[6].Cost.ToString();//update the  text box titan
            if (oreData.Count &gt; 7)
                textBox17.Text = oreData[7].Cost.ToString();//update the  text box HDT
            if (oreData.Count &gt; 8)
                textBox18.Text = oreData[8].Cost.ToString();//update the  text box liquizit
        }
    }

    private void textBox5_TextChanged(object sender, EventArgs e) // triandulis
    {

        float tempFloat;


        if (float.TryParse(textBox5.Text, out tempFloat))
        {
            oreData[2].Cost = tempFloat;
        }
        else
            MessageBox.Show("uh oh");
    }

    private void textBox6_TextChanged(object sender, EventArgs e) // eperton
    {

        float tempFloat;


        if (float.TryParse(textBox6.Text, out tempFloat))
        {
            oreData[3].Cost = tempFloat;
        }
        else
            MessageBox.Show("uh oh");
    }

    private void textBox7_TextChanged(object sender, EventArgs e) // imentium
    {

        float tempFloat;


        if (float.TryParse(textBox7.Text, out tempFloat))
        {
            oreData[4].Cost = tempFloat;
        }
        else
            MessageBox.Show("uh oh");
    }

    private void textBox8_TextChanged(object sender, EventArgs e) // stermonit
    {

        float tempFloat;


        if (float.TryParse(textBox8.Text, out tempFloat))
        {
            oreData[5].Cost = tempFloat;
        }
        else
            MessageBox.Show("uh oh");
    }

    private void textBox9_TextChanged(object sender, EventArgs e) // titan
    {

        float tempFloat;


        if (float.TryParse(textBox9.Text, out tempFloat))
        {
            oreData[6].Cost = tempFloat;
        }
        else
            MessageBox.Show("uh oh");
    }

    private void textBox10_TextChanged(object sender, EventArgs e) // HDT
    {

        float tempFloat;


        if (float.TryParse(textBox10.Text, out tempFloat))
        {
            oreData[7].Cost = tempFloat;
        }
        else
            MessageBox.Show("uh oh");
    }

    private void textBox11_TextChanged(object sender, EventArgs e) // liquizite
    {

        float tempFloat;


        if (float.TryParse(textBox11.Text, out tempFloat))
        {
            oreData[8].Cost = tempFloat;
        }
        else
            MessageBox.Show("uh oh");
    }

    private void textBox12_TextChanged(object sender, EventArgs e)
    {
        // display
    }

    private void textBox13_TextChanged(object sender, EventArgs e)
    {
        // display
    }

    private void textBox14_TextChanged(object sender, EventArgs e)
    {
        // display
    }

    private void textBox15_TextChanged(object sender, EventArgs e)
    {
        // display
    }

    private void textBox16_TextChanged(object sender, EventArgs e)
    {
        // display
    }

    private void textBox17_TextChanged(object sender, EventArgs e)
    {
        // display
    }

    private void textBox18_TextChanged(object sender, EventArgs e)
    {
        // display
    }
}
}
</code></pre>
