解决方案 »

  1.   


    if(textBox1.Text=="")
    {
        textBox1.Text=“0”;
    }
    float a=Convert.ToSingle(textBox1.Text); 
    textbox1.text不可能是null的 最多就是""
      

  2.   

    textbox1.text未被赋值前默认为空(“”),if语句没有执行,故空值转换为Single时会报错!!
      

  3.   


            if (string.IsNullOrEmpty(textBox1.Text))
            { 
               textBox1.Text=“0”;
            }
            float a=Convert.ToSingle(textBox1.Text);
      

  4.   

    float a;
    double b = float.TryParse(textBox1.Text, ref a);
    if (!b) a = 0.0f;
      

  5.   

    保险做法:
    if(textBox1.Text==null||textBox1.Text=="")
    {
       textBox1.Text=“0”;
    }
    float a=Convert.ToSingle(textBox1.Text);
      

  6.   

    textBox.Text属性什么时候返回null过?
      

  7.   

    if(textBox1.Text=="")
    {
        textBox1.Text=“0”;
    }
    float a=Convert.ToSingle(textBox1.Text); 
      

  8.   

    建议使用 float.TryParse(),如果觉得麻烦可以利用 float.TryParse() 对string扩展一个ToFilat()这样的方法
      

  9.   

    public static float ToFloat(this string str)
            {
                float i = 0f;
                float.TryParse(str, out i);
                return i;        }
      

  10.   

    +1,这样做应该可以了。
    不过最好是对Text进行格式化trim()一下,去掉前后空格,textBox1.Text.Trim()=="",不然在文本框输入一个空格,还是可能会出错。
      

  11.   

    if(textBox1.tex=="" || textBox1.text.Trim().length==0)
    {
     textBox1.Text=“0”;
    }
    float a=Convert.ToSingle(textBox1.Text);
      

  12.   

    if(textBox1.Text==null)
    {
       textBox1.Text=“0”;
    }
    float a=Convert.ToSingle(textBox1.Text);
    if判读没有进去,
    底下对一个空的值做类型转换就会失败!
      

  13.   

    不是null   是""或者string,empty
      

  14.   

    //if(textBox1.Text==null)
    //{
    //   textBox1.Text=“0”;
    //}
     float a=0;
    float.TryParse( textBox1.Text, out a);