I have System.Collections.Generic.Dictionary dict where A and B are classes, and an instance A a (where dict.ContainsKey(a)
We can't get to "IPHone" this way:
var dict = new Dictionary(StringComparer.OrdinalIgnoreCase)
{
{ "IPHone", "TCP/IP honing tools" }
};
Console.WriteLine(dict["iPhone"]); // "TCP/IP honing tools"
Console.WriteLine( ??? ); // "IPHone"
There's seems to be no O(1) solution with the current API, but looping through all entries works:
var keyValue = dict.First(p => dict.Comparer.Equals(p.Key, "iPhone"));
Console.WriteLine(keyValue.Key); // "IPHone"
Console.WriteLine(keyValue.Value); // "TCP/IP honing tools"
Or as an extension for the lazy:
[Pure]
public static KeyValuePair GetEntry(this Dictionary dictionary, TKey key)
{
var comparer = dictionary.Comparer;
return dictionary.FirstOrDefault(p => comparer.Equals(p.Key, key));
}