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();//找出不同的元素(即交集的补集)
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();//找出不同的元素(即交集的补集)