0

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 Answers 3

3
numbers[1] += 2;
Sign up to request clarification or add additional context in comments.

Comments

3

numbers[1] += 2;

That should do the trick.

Comments

3

numbers[1] += 2;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.