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