TextBox1.Text是string类型的,而c1是整型的,在VB中可以自动转换,在C#中则不行,需要强类型转换!!如:
int c1=(int)TextBox1.text;
这样就行了!很简单的问题!!:)

解决方案 »

  1.   

    try
    {
    int ce=int.parse(TextBox1.Text)
    }
    catch
    {}:)
      

  2.   

    try
    {
    string str=textBox1.text;//这样也可以嘛!
    int c1=Convert.ToInt32(str);//假如STR中非数字的话就会抛出异常!
    }
    catch(Exception exce)
    {
    .............
    }
    建意看看MSDN!
      

  3.   

    谢谢各位大虾,用dy_2000_abc(芝麻开门) 的方法,我已经把问题解决了 kinglht(爱新觉罗至尊宝)老兄
    int c1=(int)TextBox1.text;
    是不行的。显示无法转换
      

  4.   

    string s = textBox1.text.Trim();
    int i=0;
    try
    {
      i = Convert(s);
    }
    catch(Execption ex)
    {
        Respons.Write("<script>alert('"+ex.Message.Replace("'","\'")+"')</script>");
    }