I'm trying to use this code:
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");
}
to check if one of my textboxes is empty, but it gives the following error:
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
Any help?
As error clearly saying you cannot use e
because it is already used somewhere else, like in your event handler or somewhere else:
private void Form1_Load(object sender, EventArgs e)//Here for example
Try something else (c
):
controls.Where(c => String.IsNullOrEmpty(c.Text)))
You also need to add this errorProvider1.Clear();
below the controls
declaration.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With