Reputation: 5873
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"]
?
Upvotes: 5
Views: 166
Reputation: 456637
Pass an IEqualityComparer<string>
into the Dictionary
constructor, e.g., StringComparer.CurrentCultureIgnoreCase
.
Upvotes: 0
Reputation: 422026
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.
Upvotes: 12