Winform多个文本框验证是否为空

foreach (Control item in this.panel1.Controls)
{
     if (string.IsNullOrEmpty(((TextBox)item).Text))
     {
         this.label1.Text += ((TextBox)item).Name + "为空";
     }                   
}

 

用扩展方法验证空字符串:

namespace System
{
   public static class CheckStringEmpty
    {
       public static bool IsNullOrEmpty(this string str)
        {
            return string.IsNullOrEmpty(str);
        }
        
    }
}
 string str = "";
 bool b = str.IsNullOrEmpty();//true

 

 

posted @ 2013-02-18 15:47  一抹、思乡泪  Views(470)  Comments(0Edit  收藏  举报