using System.Collections.Generic;
public static void Main()
var hsFoo1 = new HashSet<Foo>(new FooEqualityComparer());
var hsFoo2 = new HashSet<Foo>(new FooEqualityComparer());
hsFoo1.UnionWith(hsFoo2);
Console.WriteLine(hsFoo1.Count);
public int ID { get; set; }
public class FooEqualityComparer
public bool Equals(Foo a, Foo b)
public int GetHashCode(Foo f)
return HashCode.Combine(f.ID);