我试过比较两个列表框的mached和not mached项目数量和项目名称。如何比较C#中两个列表框的项目名称?
我想在listMachedItems
中显示马库项目名称,马池项目数在lblMachedItemsCount
。
并在listNotMachedItems
中显示NotMached Items Name,NotMached Items Count in lblNotMachedItemsCount
。
int x = 0;
int y = 0;
for (int i = 0; i < listBox1.Items.Count; i++)
{
for (int j = 0; j < listBox2.Items.Count; j++)
{
if (listBox1.Items[i] == listBox2.Items[j])
{
y++;
//found mached items
//lblMachedItemsCount.Text = y.ToString() + " " + "items are mached";
// listMachedItems.Items.Add(listBox1.Items[i].ToString());
break;
}
else
{
x++;
//lblNotMachedItemsCount.Text = x.ToString() + " " + "items are not mached";
// listNotMachedItems.Items.Add(listBox1.Items[i].ToString());
break;
}
}
}
能否请您删除代码中的不必要的空行? –