我正在尝试使用这段代码:
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");
}
检查我的文本框是否为空,但出现以下错误:
A local or parameter named 'e' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
有什么帮助吗?
最佳答案
错误清楚地表明你不能使用 e
因为它已经在其他地方使用过,比如在你的事件处理程序或其他地方:
private void Form1_Load(object sender, EventArgs e)//Here for example
试试别的(c
):
controls.Where(c => String.IsNullOrEmpty(c.Text)))
您还需要在 controls
声明下方添加此 errorProvider1.Clear();
。
关于c# - 不能在此范围内声明名为 'e' 的局部变量或参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46246472/