سؤال

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