I have a Dictionary<string, object>
dictionary. It used to be Dictionary<Guid, object>
but other 'identifiers' have come into play and the Keys are now handled as strings.
The issue is that the Guid
keys from my source data are coming as VarChar
, so now a key of "923D81A0-7B71-438d-8160-A524EA7EFA5E"
is not the same as "923d81a0-7b71-438d-8160-a524ea7efa5e"
(wasn't a problem when using Guids).
What's really nice (and sweet) about the .NET framework is that I can do this:
Dictionary<string, CustomClass> _recordSet = new Dictionary<string, CustomClass>(
StringComparer.InvariantCultureIgnoreCase);
And that works great. But what about a nested Dictionary? Like the following:
Dictionary<int, Dictionary<string, CustomClass>> _customRecordSet
= new Dictionary<int, Dictionary<string, CustomClass>>();
How would I specify the string comparer on a nested dictionary like this?
StringComparer.InvariantCultureIgnoreCase
. This comparer is slow, as it would compare strings using character classes to overcome cross-cultural differences. This means that the wordStraße
will be treated as equal toStrasse
and vice-versa. I am assuming you do not want such behavior and if performance is crucial (if you are implementing something like a cache layer over a database) then you'd be better off by usingStringComparer.OrdinalIgnoreCase
. The ordinal comparer is the fastest string comparer the .NET framework can offer. – Wishful