views:

467

answers:

4

Hi, I am building a calculator in C#. I am not sure what the best way is to have it increment a number in an array every time the button is pressed. Here is one of my current button event handler methods:

    //Assign button '2' to 2 with array address of 1
    private void num2_Click(object sender, EventArgs e)
    {
        numbers[1] = 2;
        lblUpdate(1);
    }

I would like it so every time this button is pressed, numbers[1] gets increased by 2. Right now, it just gets set to 2 no matter how many times the button is pressed.

Thanks so much!

+3  A: 

numbers[1] += 2;

That should do the trick.

+3  A: 
numbers[1] += 2;
Kon
+3  A: 

numbers[1] += 2;

Khnle
A: 

ah haha I feel stupid. Worked! Thanks guys!

Eric