【问题标题】:incrementing array value with each button press?每次按下按钮都会增加数组值?
【发布时间】:2010-09-28 17:15:06
【问题描述】:

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

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

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

非常感谢!

【问题讨论】:

    标签: c# arrays events increment calculator


    【解决方案1】:

    数字[1] += 2;

    这应该可以解决问题。

    【讨论】:

      【解决方案2】:
      numbers[1] += 2;
      

      【讨论】:

        【解决方案3】:

        数字[1] += 2;

        【讨论】:

          猜你喜欢
          • 2016-10-02
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-04-09
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多