C# List集合求:差集、并集、交集

1、差集

1 //需引入命名空间:using System.Linq;
2 List<int> listA = new List<int>();
3 List<int> listB = new List<int>();
4 List<int> listC = listA.Except(listB).ToList();

2、并集

1 //需引入命名空间:using System.Linq;
2 List<int> listA = new List<int>();
3 List<int> listB = new List<int>();
4 List<int> listC = listA.Union(listB).ToList();

3、交集

1 //需引入命名空间:using System.Linq;
2 List<int> listA = new List<int>();
3 List<int> listB = new List<int>();
4 List<int> listC = listA.Intersect(listB).ToList();

 

posted @ 2019-09-21 17:28  陈彦斌  阅读(1986)  评论(0)    收藏  举报