我搞錯了某種字典,即應該將單詞從一個文本框轉換爲另一個文本框,而其他方式,但它並不像我我喜歡它。該按鈕的代碼是:即使「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