问题描述
大家好,
我有两个listBox(listBox3和listBox4)
listBox3中的项目总是= UPPERCASE (必须保持)
listBox4中的项目=大写和小写(不同)
listBox3中的项目必须始终存在于listBox4中
我想比较listBox3和listBox4之间的项目,所以listBox4中存在的所有不同项目,
将从listBox4中移除。
例如,之前执行代码:
listBox3:             listBox4:
   
星期一            星期一
WEDNESDAY      星期二
星期六         Wednesday
                         星期四
                         星期五&bbsp; b $ b                          星期六
                          SUNDAY
执行代码后:
listBox3:               listBox4:
   
星期一             星期一¥
星期三        周三,NBSP;      
SATURDAY          星期六
请帮助我。在此先感谢。
Hello everyone,
I have two listBoxes (listBox3 and listBox4)
Items in listBox3 are always = UPPERCASE (it must remain so)
Items in listBox4 are = Uppercase and lowercase (different)
Items in listBox3 must always exist in listBox4
I would like to compare the items between listBox3 and listBox4, so all the different items that exist in listBox4,will be removed from listBox4.
For example, before executing the code:
listBox3: listBox4:
MONDAY monday
WEDNESDAY tuesday
SATURDAY Wednesday
Thursday
Friday
saturday
SUNDAY
after executing the code:
listBox3: listBox4:
MONDAY monday
WEDNESDAY Wednesday
SATURDAY saturday
Please help me. Thanks in advance.
推荐答案
对于迟到的回复感到抱歉。
Sorry for the late reply.
为了您的目的,请参考:
For your purpose, please refer to this:
private void button1_Click(object sender, EventArgs e)
{
List<string> lb3 = new List<string>();
List<string> lb4 = new List<string>();
foreach(string str in listBox3.Items)
{
lb3.Add(str.ToLower());
}
foreach(string str in listBox4.Items)
{
lb4.Add(str.ToLower());
}
var list = lb4.Intersect(lb3).ToList<string>();//Intersection
listBox3.Items.Clear();
listBox4.Items.Clear();
foreach (string s in list)
{
listBox3.Items.Add(s.ToUpper());
listBox4.Items.Add(s);
}
}
问候,
Frankie
这篇关于c#两个listBoxes之间的比较并消除差异......?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!