Eric
Eric

Reputation: 338

incrementing array value with each button press?

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!

Upvotes: 0

Views: 2564

Answers (3)

Kevin Le - Khnle
Kevin Le - Khnle

Reputation: 10857

numbers[1] += 2;

Upvotes: 3

Kon
Kon

Reputation: 27441

numbers[1] += 2;

Upvotes: 3

Perry Neal
Perry Neal

Reputation: 765

numbers[1] += 2;

That should do the trick.

Upvotes: 3

Related Questions