How to override case sensitivity in IDictionary<string,string>

c#

Solution

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.

Problem

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"]` ?

Original source