Say you need to keep track of things you’ve already done, perhaps to avoid doing them again. What’s the fastest way to do that? HashSet<T>
seems like a natural fit, so you might choose that without a second thought. But is it faster than similar collections like Hashtable
and Dictionary<TKey, TValue>
? Today’s article puts all three to the test to see which one can insert elements, check for containment, and remove elements the quickest. Read on for the surprising results!