简体   繁体   中英

C# - How to add a number to a already existing number?

Basically my question is how i add to a number like a calculator does for example? My code currently looks like this but it does a add operation instead of adding the number behind the existing number.

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

if the user presses the button twice it would be 2. I want it to be 11. How do i do this?

You should use string variable instead int variable

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

The result of c is 2

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

If you use string it will be "11"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM