当前位置: 移动技术网 > IT编程>开发语言>.net > AspNet 集合交集、并集、差集操作

AspNet 集合交集、并集、差集操作

2018年09月19日  | 移动技术网IT编程  | 我要评论

希拉里败选后大哭,快乐大本营 张韶涵,情趣用品充气娃娃

var list1 = new list<int> { 1, 3, 5, 7, 9, 11, 13, 15 };

var list2 = new list<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
// list1:1 3 5 7 9 11 13 15
console.writeline("list1:" + string.join("\t", list1));
// list2:1 2 3 4 5 6 7 8 9
console.writeline("list2:" + string.join("\t", list2));


// 差集-list1有list2无:11 13 15
console.writeline("差集-list1有list2无:" + string.join("\t", list1.except(list2)));


// 交集-list1有list2有:1 3 5 7 9
console.writeline("交集-list1有list2有:" + string.join("\t", list1.intersect(list2)));


// 并集-包含list1和list2:1 3 5 7 9 11 13 15 2 4 6 8
console.writeline("并集-包含list1和list2:" + string.join("\t", list1.union(list2)));
console.readline();

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网