I made a custom generic list class:
class ComparableList<T> : IList<T> where T : IComparable<T>
For the generic type, I can use a type that implements IComparable directly like:
class MyComparableClass : IComparable<MyComparableClass>
or I can use a type that inherits from it:
class MyInheritedClass : MyComparableClass
I then decided that IEquatable<T>
would be better suited.
So I changed the constraint on the list class and made MyComparableClass
implement both IComparable<MyComparableClass>
and IEquatable<MyComparableClass>
.
For some reason, I can no longer use MyInheritedClass
as a generic type for the custom list unless I manually make it implement IEquatable<MyInheritedClass>
. I switched the list constraint back to IComparable<T>
and all the sudden I can use the inherited class once again.
What's so different between IComparable<T>
and IEquatable<T>
that makes the rules different?