mardi 6 octobre 2015

How to create a conditional-OR if statement that runs multiple times if multiple conditions are true

Right now my code has 52 checkboxes that each return their own value.

if (checkedListBox1.GetItemCheckState(0) == CheckState.Checked)
            {
                x += 1;
            }
if (checkedListBox1.GetItemCheckState(1) == CheckState.Checked)
            {
                x += 2;
            }
if (checkedListBox1.GetItemCheckState(2) == CheckState.Checked)
            {
                x += 1;
            }

I want to group if statements that do the same thing into a single statement, something like

if (checkedListBox1.GetItemCheckState(0) == CheckState.Checked ||
    checkedListBox1.GetItemCheckState(2) == CheckState.Checked ||
    checkedListBox1.GetItemCheckState(17) == CheckState.Checked )
            {
                x += 1;
            }

However such a code would only run once. Is there an operator that would help in this situation or would I have to just write 52 if statements.

Aucun commentaire:

Enregistrer un commentaire