プログラムがデータをインポートするためのファイル パスである複数のテキスト ボックスを含むフォームがあります。現在、長さがゼロでないかどうかは、次の方法でチェックされています。
//this code imports the files required by the user, as specified in the
//file path text boxes
private void btImport_Click(object sender, EventArgs e)
{
bool hasPath = false;
foreach (TextBox box in this.gbPaths.Controls.OfType<TextBox>().Where(tb => tb.Text.Length > 0))
{
hasPath = true;
//import code
}//end foreach
if (!hasPath)
{
MessageBox.Show("You must enter at least one file path.");
}//end if
}//end import code
私が疑問に思っているのは、その//import code
部分を次のようなものに置き換えることができるかということです:
if(tb.Name = "txtAvF") then...
または同様の、または foreach ループの外でそれを行う必要がありますか? 前もって感謝します。何か明確にする必要がある場合はお知らせください。