我正在尝试使用这段代码:
var controls = new[] { txtName, txtIdentityCard, txtMobile1 };
foreach (var control in controls.Where(e => String.IsNullOrEmpty(e.Text))) // error here in (e)
{
errorProvider1.SetError(control, "Please fill the required field");
}
检查我的文本框之一是否为空,但出现以下错误:
不能在此范围内声明名为“e”的本地或参数
因为该名称在封闭的本地范围中使用来定义
本地或参数
有什么帮助吗?
由于错误清楚地表明您无法使用e
因为它已经在其他地方使用,例如在您的事件处理程序或其他地方:
private void Form1_Load(object sender, EventArgs e)//Here for example
尝试其他方法(c
):
controls.Where(c => String.IsNullOrEmpty(c.Text)))
你还需要添加这个errorProvider1.Clear();
以下controls
宣言。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)