Question

I need to determine whether a Dictionary I receive in a function has a case-insensitive comparer.

ie. A case insensitive dictionary is declared like so:

var myDict = new Dictionary<string, decimal>(StringComparer.OrdinalIgnoreCase);

When I receive the dictionary into my function I can access the .Comparer property and check its type - however all I seem to get is -

System.Collections.Generic.EqualityComparer<string> 

How can I find out if the Comparer being used is StringComparer.OrdinalIgnoreCase?

Was it helpful?

Solution

You should check the value, not the type against StringComparer.OrdinalIgnoreCase.

myDict.Comparer == StringComparer.OrdinalIgnoreCase
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top