刚接触.NET,请各位高人指教!
有如下判断是否为数字函数:
private bool IsNumeric(string str)
    {
        if (str == null || str.Length == 0)
            return false;
        System.Text.ASCIIEncoding ascii = new System.Text.ASCIIEncoding();
        byte[] bytestr = ascii.GetBytes(str);
        foreach (byte c in bytestr)
        {
            if (c < 48 || c > 57)
            {
                return false;
            }
        }
        return true;
    } 请问下面这段应该怎么写?
protected void Button2_Click(object sender, EventArgs e)
    {
        int total=Convert.ToInt32(Label2.Text);
        int t2 = Convert.ToInt32(TextBox2.Text);
        int t3 = Convert.ToInt32(TextBox3.Text);
        if (IsNumeric(t2))
        {
            total="Please input a number";
        }
        else
        {
            total = t2 * t3;  
        }       
    }

解决方案 »

  1.   

    IsNumeric()的行参是string 型,而你实参是int
      

  2.   

    protected void Button2_Click(object sender, EventArgs e)
        {
           
            if (IsNumeric(TextBox2.Text) && IsNumeric(TextBox3.Text))
            {
                total="Please input a number";
            }
            else
            {
                int total= Convert.ToInt32(TextBox2.Text)*Convert.ToInt32(TextBox3.Text);
            }