[英]How do I determine type of Dictionary comparer in C#?
I need to determine whether a Dictionary I receive in a function has a case-insensitive comparer. 我需要确定我在函数中收到的Dictionary是否具有不区分大小写的比较器。
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 - 当我收到字典到我的函数中时,我可以访问.Comparer属性并检查它的类型 - 但是我似乎得到的只是 -
System.Collections.Generic.EqualityComparer<string>
How can I find out if the Comparer being used is StringComparer.OrdinalIgnoreCase? 如何确定使用的Comparer是否为StringComparer.OrdinalIgnoreCase?
您应该检查值,而不是StringComparer.OrdinalIgnoreCase的类型。
myDict.Comparer == StringComparer.OrdinalIgnoreCase
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.