C#中关于List的并集与交集以及差集解析
导读:收集整理的这篇文章主要介绍了C#中关于List<T>的并集与交集以及差集解析,觉得挺不错的,现在分享给大家,也给大家做个参考。集合的并集是合并集合的项,如下图所示:List<int> ls1 = new List&l...
收集整理的这篇文章主要介绍了C#中关于ListT>
的并集与交集以及差集解析,觉得挺不错的,现在分享给大家,也给大家做个参考。集合的并集是合并集合的项,如下图所示:Listint>
ls1 = new Listint>
() {
1,2,3,5,7,9 }
;
Listint>
ls2 = new Listint>
() {
2,4,6,8,9,10}
;
IEnumerableint>
unionLs = ls1.Union(ls2);
foreach (int ITem in unionLs){
Console.Write("{
0}
\t", item);
}
集合的交集是取集合的共同的项,如下图所示:
Listint>
ls1 = new Listint>
() {
1,2,3,5,7,9 }
;
Listint>
ls2 = new Listint>
() {
2,4,6,8,9,10}
;
IEnumerableint>
intersectLs = ls1.Intersect(ls2);
foreach (int item in intersectLs){
Console.Write("{
0}
\t",item);
}
集合的差集是取在该集合中而不在另一集合中的所有的项,如下图所示:
Listint>
ls1 = new Listint>
() {
1,2,3,5,7,9 }
;
Listint>
ls2 = new Listint>
() {
2,4,6,8,9,10}
;
IEnumerableint>
exceptLs = ls1.Except(ls2);
foreach (int item in exceptLs){
Console.Write("{
0}
\t", item);
}
以上就是C#中关于ListT> 的并集与交集以及差集解析的详细内容,更多请关注其它相关文章!
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: C#中关于List
本文地址: https://pptw.com/jishu/592874.html
