-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: Implementing IComparable should implement comparison operators #8633
Comments
At the very least, automatically overloading |
Even with generics that would be a breaking change. The following is legal today and does perform a reference equality check: public static bool IsEquals<T>(T x, T y) where T : class, IComparable<T>
{
return x == y;
} If the compiler would instead invoke |
Was not considering this issue very deeply, and you're both definitely right. Maybe it should be limited to |
Also what those operators actually mean in the context of that object should be left for the programmer designing those objects. |
The proposed change would break existing programs. |
Implementing IComparable is sufficient for allowing comparison of two instances of class X.
It is, therefore, preferable that comparison operators (such as !=, =, <, <=, etc.) would be auto-implemented for X pairs when implementing IComparable.
Currently, large share of comparable classes features the following silly-looking pattern:
Moreover, by adding this feature, the following will be possible:
This is not such a drastic change but it'll be handy 😄
The text was updated successfully, but these errors were encountered: