How can I check if a string is a number?

后端 未结 25 1863
伪装坚强ぢ
伪装坚强ぢ 2020-11-27 21:04

I\'d like to know on C# how to check if a string is a number (and just a number).

Example :

141241   Yes
232a23   No
12412a   No

an

25条回答
  •  情书的邮戳
    2020-11-27 21:15

    Try This

    here i perform addition of no and concatenation of string

     private void button1_Click(object sender, EventArgs e)
            {
                bool chk,chk1;
                int chkq;
                chk = int.TryParse(textBox1.Text, out chkq);
                chk1 = int.TryParse(textBox2.Text, out chkq);
                if (chk1 && chk)
                {
                    double a = Convert.ToDouble(textBox1.Text);
                    double b = Convert.ToDouble(textBox2.Text);
                    double c = a + b;
                    textBox3.Text = Convert.ToString(c);
                }
                else
                {
                    string f, d,s;
                    f = textBox1.Text;
                    d = textBox2.Text;
                    s = f + d;
                    textBox3.Text = s;
                }
            }
    

提交回复
热议问题