I was looking around for a way to have a dictionary key/hash set string
be case insensitive. I found many answers around on SO and even on the MS website.
From what I've seen, it seems like the answers are saying that by setting the IEqualityComparer<TKey>
to StringComparer.CurrentCultureIgnoreCase
(or something similar) for Dictionary
and HashSet
, this will make it as if the key set will be case insensitive. But no, they are saying that it sets the equality operator, which is different.
Hash sets that I'm familiar with convert the key object into a hashed numeric value which is then used to access a bucket that may contain the key that you are looking for. Then the equality operator is then used to check if that bucket actually contains the value you are looking for.
If this is the case, then it would be conceivable that a
and A
could be in different buckets, thus allowing the two items to be added without conflict, or checked upon and not finding the other. I have to assume that this is not the case as this would break a lot of code out there, so what is really happening here? What's happening behind the curtain?