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

浙公网安备 33010602011771号