每次按下按钮都会增加数组值?

发布于 2024-07-11 02:42:01 字数 349 浏览 8 评论 0原文

我正在用 C# 构建一个计算器。 我不确定最好的方法是什么,让它在每次按下按钮时增加数组中的数字。 这是我当前的按钮事件处理程序方法之一:

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

我希望每次按下此按钮时,数字 [1] 都会增加 2。现在,无论按下按钮多少次,它都会设置为 2 。

非常感谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

抠脚大汉 2024-07-18 02:42:01
numbers[1] += 2;
numbers[1] += 2;
涙—继续流 2024-07-18 02:42:01

数字[1] += 2;

这应该够了吧。

numbers[1] += 2;

That should do the trick.

东北女汉子 2024-07-18 02:42:01

数字[1] += 2;

numbers[1] += 2;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文