我有一个groupBox1,其中有多个textBox,如何判断 这些textBox的Text属性全值为空?
给点思路?  我是菜鸟~~~~

解决方案 »

  1.   

    bool empty = groupBox1.Controls.Cast<Control>()
                 .All(c => c is TextBox && (c as TextBox).Text.Length == 0)
      

  2.   


    bool empty = groupBox1.Controls.Cast<Control>().Where(c => c is TextBox)
                 .All(c=>(c as TextBox).Text.Length == 0);
      

  3.   


    但是它报错,System.Windows.Form.Control.ControlCollection不包含"Cast"的定义,
      

  4.   

    bool isEmpty;
    foreach(Control c in  groupBox1.Controls)
    {
       if(c is TextBox)
       {
           if(string.IsNullOrEmpty(c.Text))
           {
                isEmpty=true;
           }
           else
           {
                isEmpty=false;
           }
       }
    }
      

  5.   

    如果把   bool empty = groupBox1.Controls.Cast<Control>().All(c => c is TextBox && (c as TextBox).Text.Length == 0);
    作为全局变量 ,则回报错 "字段初始值无法引用非静态字段、属性、方法 WindowsFormsApplication1.Form1.GroupBox1";如果把  bool empty = groupBox1.Controls.Cast<Control>().All(c => c is TextBox && (c as TextBox).Text.Length == 0);
    放到一个方法或者事件中,则报错"System.Windows.Form.Control.ControlCollection不包含"Cast"的定义" 
    这是怎么回事啊?
      

  6.   


    using System.Linq; VS2005可以用6#的