我已經得到了一個窗體,其中包含多個文本框,這些文本框是程序從中導入數據的文件路徑。目前,他們被檢查非零長度如下:C#文本框文件導入
//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循環之外做到這一點?提前致謝。讓我知道是否需要澄清任何事情。
你能澄清你想要做什麼? 「txtAvF」的意義是什麼?進口過程的性質是什麼? – Ani 2010-10-26 03:25:21
它將從幾個不同的來源導入,因爲需要比較實際信息和預測信息,並且此數據存儲在幾個不同的文件中。因此,當它通過循環時,它需要動態確定正在導入六個可能文件中的哪一個。它可能應該是一個開關盒,而不是一個if。我的錯。 – mispecialist 2010-10-26 03:45:29