Union将多个集合合并为一个集合,并返回具有唯一元素的结果集合
相交返回在两个输入序列中都通用的序列元素
从第二个输入序列中不存在的,从第一个输入序列中返回的序列元素除外
class Program{ static void Main(){ int[] count1 = { 1, 2, 3, 4 }; int[] count2 = { 2, 4, 7 }; var resultUnion = count1.Union(count2); var resultIntersect = count1.Intersect(count2); var resultExcept = count1.Except(count2); System.Console.WriteLine("Union"); foreach (var item in resultUnion){ Console.WriteLine(item); } System.Console.WriteLine("Intersect"); foreach (var item in resultIntersect){ Console.WriteLine(item); } System.Console.WriteLine("Except"); foreach (var item in resultExcept){ Console.WriteLine(item); } Console.ReadKey(); } }
输出结果
Union 1 2 3 4 7 Intersect 2 4 Except 1 3