码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2018-09-18 22:36:27      阅读:424      评论:0      收藏:0      [点我收藏+]

标签:exce   new   int   包含   union   str   ring   string   line   

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();

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

标签:exce   new   int   包含   union   str   ring   string   line   

原文地址:https://www.cnblogs.com/Cailf/p/9671200.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!