Skip to main content
2 of 3
quoted OP's code
t3chb0t
  • 44.7k
  • 9
  • 84
  • 191

Don't test whether a HashSet contains a key if you want to remove it.
Instead, just straight try to remove it, halving your work.

if(list.Contains(value)) {
    list.Remove(value);
}

Becomes

list.Remove(value);
Deduplicator
  • 19.9k
  • 1
  • 32
  • 65