List<int> a = 1,2,3
List<int> b = 2,4,5
output
1,3,4,5
答案 0 :(得分:38)
答案 1 :(得分:4)
尝试并测试:
List<int> a = new List<int>(){1, 2, 3};
List<int> b = new List<int>(){2, 4, 5};
List<int> c = a.Except(b).Union(b.Except(a)).ToList();
答案 2 :(得分:0)
另一种方式:
List<int> a = new List<int> { 1, 2, 3 };
List<int> b = new List<int> { 2, 4, 5 };
var nonIntersecting = a.Union(b)
.Where(x => !a.Contains(x) || !b.Contains(x));