Yes, the StringComparer
class provides a bunch of convenient StringComparer
instances (which implement IComparer<string>
) that does case-insensitive comparison:
CurrentCultureIgnoreCase
InvariantCultureIgnoreCase
OrdinalIgnoreCase
Without knowing any more of your use case, I can't tell you which comparer you want to use. You need to think about which culture (or the invariant culture) you want the comparison to be in, or whether you want a simple ordinal comparison.
That said, Dictionary
doesn't accept an IComparer
, but an IEqualityComparer
... But you can still use StringComparer
nonetheless, it also implements IEqualityComparer
.