我已经得到了一个窗体,其中包含多个文本框,这些文本框是程序从中导入数据的文件路径。目前,他们被检查非零长度如下: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