Finding symmetric difference with LINQ

Use HashSet<T> directly – it has a SymmetricExceptWith method: HashSet<T> data = new HashSet<T>(a); data.SymmetricExceptWith(b); EDIT: If you want to maintain the order, here’s an alternative: HashSet<T> data = new HashSet<T>(a); data.IntersectWith(b); foreach (T t in a.Concat(b)) { if (!data.Contains(t)) { yield return t; } } This has the following important differences: Both a and … Read more

sql joins as venn diagram

I agree with Cade about the limitations of Venn diagrams here. A more apposite visual representation might be this. Tables SELECT A.Colour, B.Colour FROM A CROSS JOIN B SQL Fiddle The cross join (or cartesian product) produces a result with every combination of the rows from the two tables. Each table has 4 rows so … Read more