質問

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?

役に立ちましたか?

解決

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

myDict.Comparer == StringComparer.OrdinalIgnoreCase
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top