List<int> a = 1,2,3
List<int> b = 2,4,5
output
1,3,4,5
经过验证和测试:
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();
另一种方式:
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));