using System.Collections.Generic;
public static void Main()
var C1= new Combination{Id=1, CombOne=1, CombTwo=2};
var C2= new Combination{Id=2, CombOne=2, CombTwo=1};
var C3= new Combination{Id=3, CombOne=1, CombTwo=2};
var C4= new Combination{Id=4, CombOne=3, CombTwo=3};
var C5= new Combination{Id=5, CombOne=2, CombTwo=1};
var list = new List<Combination> { C1, C2, C3, C4, C5 };
var set = new HashSet<Combination>(new CombinationComparer());
var invalid = list.Aggregate(new List<Combination>(list.Count),
Console.WriteLine(string.Join( ",", invalid.Select(c => c.Id)));
public int Id { get; set; }
public int CombOne { get; set; }
public int CombTwo { get; set; }
public class CombinationComparer : IEqualityComparer<Combination>
public bool Equals(Combination c1, Combination c2)
if (ReferenceEquals(c1,c2))
if (c1 == null || c2 == null)
return (c1.CombOne == c2.CombOne && c1.CombTwo == c2.CombTwo)
|| (c1.CombOne == c2.CombTwo && c1.CombTwo == c2.CombOne);
public int GetHashCode(Combination c)
return c.CombOne.GetHashCode() + c.CombTwo.GetHashCode();