1 //Intersect 交集,Except 差集,Union 并集 2 int[] a = { 1, 2, 3, 4, 5 ,6}; 3 int[] b = { 2, 4, 5,6, 7, 8, 9 }; 4 var jiaoJi = a.Intersect(b).ToList();//交集:2,4,5,6 5 var aChaJi = a.Except(b).ToList();//差集:1,3 6 var bChaJi = b.Except(a).ToList();//差集:7,8,9 7 var bingJi = a.Union(b).ToList();//并集:1,2,3,4,5,6,7,8,9 8 9 string s = ""; 10 for (int i = 0; i < jiaoJi.Count; i++) 11 { 12 s += jiaoJi[i] + ","; 13 } 14 Console.WriteLine("交集:"+s); 15 string s1 = ""; 16 for (int i = 0; i < aChaJi.Count; i++) 17 { 18 s1 += aChaJi[i] + ","; 19 } 20 Console.WriteLine("差集:" + s1); 21 string s2 = ""; 22 for (int i = 0; i < bChaJi.Count; i++) 23 { 24 s2 += bChaJi[i] + ","; 25 } 26 Console.WriteLine("差集:" + s2); 27 string s3 = ""; 28 for (int i = 0; i < bingJi.Count; i++) 29 { 30 s3 += bingJi[i] + ","; 31 } 32 Console.WriteLine("并集:" + s3); 33 Console.Read();