So if I understand it correctly you want a dictionary that holds strings as they are, but hashes in a case-insensitive manner, such that you can still search in O(1) amortized time regardless of case?
The way I see it you need to pass a custom IEqualityComparer
when creating the Dictionary
with this constructor and when implementing the IEqualityComparer
treat strings as if they are all upper or lower case for example and the same for the hash code (i.e. return the hash code of the string turned to upper case).
For example:
class MyComparer : IEqualityComparer<string>
{
public bool Equals(string x, string y)
{
return x.ToUpper() == y.ToUpper();
}
public int GetHashCode(string obj)
{
return obj.ToUpper().GetHashCode();
}
}
...
Dictionary<String, String> dict = new Dictionary<string, string>(new MyComparer());
Now practically your dictionary holds the strings normally but when searching or adding it treats them as if they are all uppercase so "AbcD" is treated the same as "aBCd" (both as "ABCD").