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