Disclaimer: Maybe be micro-YAGNI-optimizing but hear me out ..
The problem is to implement a case-insensitive lookup table.
- My old-skool way: While populating the dictionary, upper-case the key before inserting. Upper-case the key when someone gives you a key to lookup.
- The new way (I learned about it today): Dictionary takes in an IComparer implementation, so I could pass in
StringComparer.InvariantCultureIgnoreCase
. I think it would delegate to String.Compare(x, y, SomeIgnoreCaseEnum)
The new way has an advantage in that I don't need to ensure that a .ToUpper() is performed at each of the n places where a lookup is done against the dictionary .
My question is which one is more efficient ? Just curious I guess...
Update: Note I don't need to know the original key that was inserted. Also the keys that are used are culture agnostic.