using System; using System.Linq; namespace ConsoleApp2 { internal class Program { static void Main(string[] args) { string[] arr1 = new[] { "1", "2", "3", "4", "5" }; string[] arr2 = new[] { "1", "3", "5" }; //找出相同元素(即交集) //var sameArr = arr1.Intersect(arr2).ToArray(); //找出不同的元素(即交集的补集) var diffArr = arr1.Where(c => !arr2.Contains(c)).ToArray(); for (int i = 0; i < diffArr.Length; i++) { Console.WriteLine(diffArr[i]); } Console.ReadKey(); } } }
标签:diffArr,C#,补集,交集,arr2,arr1,string From: https://www.cnblogs.com/duhaoran/p/17049094.html