Search code examples
c#.neticomparable

IComparable and IComparable<T>


Should I implement both IComparable and the generic IComparable<T>? Are there any limitations if I only implement one of them?


Solution

  • Yes, you should implement both.

    If you implement one, any code that depends on the other will fail.

    There is lots of code that uses either IComparable or IComparable<T> but not both, so implementing both ensure your code will work with such code.