List<T>取交集、差集、并集

1.  取交集 (A和B都有)

List A : { 1 , 2 , 3 , 5 , 9 }
List B : { 4 , 3 , 9 }
var intersectedList = list1.Intersect(list2);
结果 : { 3 , 9 }
判断A和B是否有交集 bool isIntersected = list1.Intersect(list2).Count() > 0

2. 取差集 (A有,B沒有)
List A : { 1 , 2 , 3 , 5 , 9 }
List B : { 4 , 3 , 9 }
 var expectedList = list1.Except(list2);
结果 : { 1 , 2 , 5 }
判断A和B是否有差集 bool isExpected = list1.Expect(list2).Count() > 0

 3.  取联集 (包含A和B)

var unionList =list1.Union(list2);

原文地址:https://www.cnblogs.com/50614090/p/2169019.html