Type Summary

						public interface IComparable
{
  // Methods
     int CompareTo (object obj);
}

BA There is a natural tension between modeling a concept as an interface and as a base class. In this case it is clear that requiring developers to inherit from a Comparable base class to be comparable would have been too restrictive. However, this class does illustrate good design principles for any interface. It is simple; there are no complex contracts to be maintained between the members of the interface (because there is only one member). The concept is clearly an additive element of the class design rather than the center point of the design.

JR When defining a value type that implements IComparable, you should define a type-safe version of the method ...

Get .NET Framework Standard Library Annotated Reference, Volume 1: Base Class Library and Extended Numerics Library now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.