[Proposal] Use CompareTo to resolve missing comparison operators
- Dominant language
- No language data
- Stars
- 328
- Forks
- 71
- PR merge metrics
- No merged PRs in 30d
Description
Given this class that implements the IComparable:
```vb.net
Class Test
Implements IComparable(Of Integer)
Public Value As Integer
Public Function CompareTo(other As Integer) As Integer Implements IComparable(Of Integer).CompareTo
Return Value.CompareTo(other)
End Function
End Class
```
Why can't c# use to the CompareTo method to resolve the comparison operators?
``` vb.net
Dim t As New Test With {.Value = 1}
Console.WriteLine( f = 1)
Console.WriteLine( f <> 1)
Console.WriteLine(f > 1)
Console.WriteLine(f >= 1)
Console.WriteLine(f < 1)
Console.WriteLine(f <= 1)
```
which can be lowered to:
``` vb.net
Dim t As New Test With {.Value = 1}
Console.WriteLine(f.CompareTo(1) = 0)
Console.WriteLine(f.CompareTo(1) <> 0)
Console.WriteLine(f.CompareTo(1) = 1)
Console.WriteLine(f.CompareTo(1) <> -1)
Console.WriteLine(f.CompareTo(1) = -1)
Console.WriteLine(f.CompareTo(1) <> 1)
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.