我在c#中創建一個考試系統。我正在創建結果,我在listbox1中有答案,在另一個listbox2中有正確的答案,我的問題是應該比較列表框中的值,並且應該在其基礎上生成結果。如果一半的數值符合學生通過否則失敗。 我的代碼如下,但它不起作用。匹配lisboxes項目並創建結果
for(int intCount = 0; intCount < listBoxSanswers.Items.Count;intCount++)
{
for (int intSubCount = 0; intSubCount < listBoxActAnswers.Items.Count; intSubCount++)
{
if (listBoxActAnswers.Items[intCount].ToString() == listBoxActAnswers.Items[intSubCount].ToString())
{
listBox3.Items.Add(listBoxActAnswers.Items[intCount].ToString());
}
}
}
在你的if語句中,兩個列表中的一個應該是「listBoxSanswers」 – Bambuk
當你說「它不工作」時,你的意思到底是什麼?錯誤是被拋出還是你沒有得到你期望的結果? – RH6
不起作用意味着它不會複製第三個列表框中的兩個列表框的常用項目。我想要比較listbox1和listbox2的項目,並將常見項目添加到listbox3。 –