dotnet / dotnet/vblang

[Proposal] Use CompareTo to resolve missing comparison operators

Open
#583 6 comments 0 reactions 0 assignees View on GitHub
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.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.