CA1036: Override methods on comparable types
- Dominant language
- C#
- Stars
- 7.7k
- Forks
- 1.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 61
Description
Link to the issue description: https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1036
### Rule Description
> Types that define a custom sort order implement the [IComparable](https://learn.microsoft.com/en-us/dotnet/api/system.icomparable) interface. The [CompareTo](https://learn.microsoft.com/en-us/dotnet/api/system.icomparable.compareto) method returns an integer value that indicates the correct sort order for two instances of the type. This rule identifies types that set a sort order. Setting a sort order implies that the ordinary meaning of equality, inequality, less-than, and greater-than don't apply. When you provide an implementation of [IComparable](https://learn.microsoft.com/en-us/dotnet/api/system.icomparable), you must usually also override [Equals](https://learn.microsoft.com/en-us/dotnet/api/system.object.equals) so that it returns values that are consistent with [CompareTo](https://learn.microsoft.com/en-us/dotnet/api/system.icomparable.compareto). If you override [Equals](https://learn.microsoft.com/en-us/dotnet/api/system.object.equals) and are coding in a language that supports operator overloads, you should also provide operators that are consistent with [Equals](https://learn.microsoft.com/en-us/dotnet/api/system.object.equals).
Contributor guide
Assessment
This issue has not been assessed yet.