Add numbers in c#

后端 未结 7 1024
难免孤独
难免孤独 2020-12-21 12:19

i have a numerical textbox which I need to add it\'s value to another number I have tried this code

String add = (mytextbox.Text + 2)

but

7条回答
  •  滥情空心
    2020-12-21 13:06

    int intValue = 0;
    if(int.TryParse(mytextbox.Text, out intValue))
    {
        String add = (intValue + 2).ToString();
    }
    

    I prefer TryPase, then you know the fallback is going to be zero (or whatever you have defined as the default for intValue)

提交回复
热议问题