C# - 如何在现有号码中添加号码?

时间:2017-03-27 03:27:20

标签: c#

基本上我的问题是我如何添加像计算器这样的数字?我的代码目前看起来像这样,但它执行添加操作,而不是添加现有数字后面的数字。

    private void button1_Click(object sender, RoutedEventArgs e)
    {
            value1 = value1 + 1;
            output = value1;
            textresult.Text = output.ToString();

如果用户按下按钮两次,那就是2.我希望它是11.我该怎么做?

1 个答案:

答案 0 :(得分:1)

您应该使用字符串变量而不是int变量

int a = 1;
int b = 1;
int c = a+b;

c的结果是2

string a = "1";
string b = "1";
string c = a+b;

如果你使用字符串,它将是" 11"