Q:

How to assign a value to a checkbox and use it in a formula?

I'm very new to all this programming and c# windows application, so go easy on me.
Basically I have 13 checkboxes which I want to assign values to, so when the checkboxes are checked those value goes into a formula:
consumption = energy * 15 / 1000

The "energy" is representing the checkboxes. I want all checked checkBoxes values to go there.
If its not possible to assign a value, what is the best way of doing it?
The only way I know is doing the following for each one:
if (checkBox1.CheckState == CheckState.Checked)
{
       energy += energy + 1200; 
}

I would like to do a foreach method but I don't know how to.

A:

You can store the values in the Tag property of the Checkbox control and you can do a foreach on Form.Controls check if it is an instance of CheckBox and perform your logic.
An example
    int energy = 0;
foreach(Control control in this.Controls)
{
    //you can have additional checks like name starts with to identify energy checkboxes
    if (control is CheckBox) 
    {
        energy = energy + Convert.ToInt32(control.Tag);
    }
}

