2017-09-15 46 views
-1

に宣言することはできません私はこのコードを使用しようとしている:私のテキストボックスのいずれかが空であるが、それは次のエラーを与えるかどうかを確認するために「E」という名前のローカルまたはパラメータがこの範囲

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

助けてください?

答えて

0

あなたのイベントハンドラ内またはどこかのようなエラーが明らかに、それはすでにどこかで使用されているので、あなたがeを使用することはできません言うように:

private void Form1_Load(object sender, EventArgs e)//Here for example 

何か他のもの(c)を試してみてください。

controls.Where(c => String.IsNullOrEmpty(c.Text))) 

controls宣言の下に、これを追加する必要があります。errorProvider1.Clear();

+0

他にもいろいろあります。コードは1つずつうまく動作します...すべてのテキストボックスにエラーを設定する必要があります。そのうちの1つがいっぱいになるとエラーマークがクリアされます –

+0

@a_fathyこの 'errorProvider1.Clear();を以下の' var controls = new [] {txtName、txtIdentityCard、txtMobile1}; 'と' foreach'の上に追加してください。 –

関連する問題