.NET Dictionary with Case-Insensitive Comparison
Tuesday, March 24th, 2009How do you create a IDictionary that does case-insensitive key matches. There are a number of solutions posted on the web, but none of them seem quite correct. The following should work.
IDictionary
where
public class StringCompInsensitive : IEqualityComparer{ public bool Equals(string x, string y) { return String.Compare(x, y, true) == 0; } public int GetHashCode(string obj) { return ((string)obj).ToLower().GetHashCode(); } }