我搞错了某种字典,即应该将单词从一个文本框转换为另一个文本框,而其他方式,但它并不像我我喜欢它。该按钮的代码是:即使“if”为真,“else”也会完成
private void button1_Click(object sender, EventArgs e)
{
string[] lines = File.ReadAllLines("C:/words.txt");
int i = 0;
var items = from line in lines
where i++ != 0
let words = line.Split('|')
where words.Count() > 1
select new
{
word = words[0],
translation = words[1]
};
foreach (var item in items)
{
if (textBox1.Text == item.word)
{
textBox2.Text = item.translation;
}
if (textBox2.Text == item.translation)
{
textBox1.Text = item.word;
}
else
{
label3.Text = ("not found");
}
}
}
编辑:不适用于“else if”。
你应该用你正在使用的语言标记你的问题。 – assylias 2012-04-15 12:54:00
欢迎来到SO。如果您说明您使用哪种语言,这将有所帮助。标签“split”和“translate”似乎不适合。 – dgw 2012-04-15 12:56:06