显示两个数组中不匹配的值 [英] Show non matched values from two arrays
本文介绍了显示两个数组中不匹配的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将每个数组中没有对的项目放入 ListBox
的集合中?
How do I put into the collection of ListBox
those items that doesn't have a pair from each array?
例如:
第一个数组= 100500
first array = 100 500
第二个数组= 100200300400500600700800
second array = 100 200 300 400 500 600 700 800
现在,如何将那些不匹配的值(200,400,600,700,800)
显示在 ListBox
中?
Now, how do I show those non matched values (200,400,600,700,800)
into ListBox
?
推荐答案
您可以使用LINQ和 Except
方法:
You can use LINQ and Except
method:
int[] result = secondArray.Except(firstArray).ToArray();
yourListBox.DataSource = result;
此外,如果要在 firstArray
中包含不在 secondArray
中的值,请使用以下查询:
Also if you want to include values in firstArray
that are not in secondArray
go with the following query:
var result = firstArray.Except(secondArray).Union(secondArray.Except(firstArray)).ToArray();
这篇关于显示两个数组中不匹配的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文