If I have a Dictionary<char,...>
is it possible to make method ContainsKey case-insensitive?
I know, in Dictionary<string,...>
is used StringComparer.InvariantCultureIgnoreCase, but what to do when key in dictionary is char-type?
The Dictionary class has a constructor that takes any IEqualityComparer
. What you need to do is implement a simple case-insensitive IEqualityComparer<char>
and pass it to the constructor, and it will be used when evaluating the key.
This is a similar question for implementing IComparer<char>
without case sensitivity. IEqualityComparer
will be practically identical:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With