HashSets don't keep the elements unique if you mutate their identity
问题 When working with HashSets in C#, I recently came across an annoying problem: HashSets don't guarantee unicity of the elements; they are not Sets. What they do guarantee is that when Add(T item) is called the item is not added if for any item in the set item.equals(that) is true . This holds no longer if you manipulate items already in the set. A small program that demonstrates (copypasta from my Linqpad): void Main() { HashSet<Tester> testset = new HashSet<Tester>(); testset.Add(new Tester(1