tags:

views:

208

answers:

3
List<int> a = 1,2,3
List<int> b = 2,4,5

output
1,3,4,5
+4  A: 

Tried and tested:

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();
Mitch Wheat
i want to find the non intersecting part
I've updated my answer.
Mitch Wheat
Reed Copsey's answer is the better one!
Mitch Wheat
+1 for a good answer, despite the 'better' answer.
Mike Christiansen
+12  A: 

The trick is to use Except with the intersection of the two lists.

This should give you the list of non-intersecting elements:

var nonIntersecting = a.Union(b).Except(a.Intersect(b));
Reed Copsey
A: 

Another way :

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));
çağdaş