My IEquatable still uses Object.GetHashcode for the dictionary <T> []
I have something like the following to be the key to the generic dictionary.
class IMyClass<T> : IEquatable<IMyClass> where T : struct
{
//etc
}
class MyClass<T> : IMyClass<T> where T : struct
{
public bool Equals(IRatingKey<T> other)
{
//etc
}
}
From what I understand in EqualityComparer<T>.Default, he should see what I have implemented IEquatable<T>and, therefore, create EqualityComparer on the fly.
Dictionary<TKey, TValue>an equality implementation is required to determine if the keys are the same. If the comparison is set to null, the constructor uses the standard divisor equalityEqualityComparer<T>.Default. If the typeTKeyimplements aSystem.IEquatable<T>common interface, the equality equalizer uses this implementation by default.
However, from what I see in using a dictionary indexer Dictionary<T>[], it still relies on an override of GetHashcode, e.g.public override int GetHashCode()
, , . , IEquatable MyClass, IMyClass? IMyClass, .
IEqualityComparer, , , .