I have dictionary entries that are read to a Dictionary <string,string> myDict=null;
The entries are like:
"user","Anthony"
"lastLogin","May 10 2010 20:43"
How would I retrieve lastLogin
with lowercase key myDict["lastlogin"]
?
The key is handled in a case-insensitive manner; it is translated to lowercase before it is used.
All Dictionaries are case-sensisitive.
User metadata keys are case insensitive and are returned as lowercase strings, even if they were originally specified with uppercase strings.
A Python dictionary sub-class that is case-insensitive when searching, but also preserves the keys as inserted. when keys are listed, ie, via keys() or items() methods. pair as the key's value (values become dictionaries).
A constructor for Dictionary<TKey,TValue>
takes a comparer object. You simply need to pass whatever comparer you want to it.
var dic = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
Of course, you may want to pass things like CurrentCultureIgnoreCase
or InvariantCultureIgnoreCase
depending on your need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With