Home > Blockchain >  How to control the equality of mutiple tuples?
How to control the equality of mutiple tuples?

Time:01-01

Imports System

Class RGB
  Public Shared ReadOnly Dim Red As New RGB(255, 0, 0)
  Public Shared ReadOnly Dim Green As New RGB(0, 255, 0)
  Public Shared ReadOnly Dim Blue As New RGB(0, 0, 255)

  Private R, G, B As Byte

  Sub New(ByVal R As Byte, G As Byte, B As Byte)
    Me.R = R
    Me.G = G
    Me.B = B
  End Sub

  Function IsSameColorWith(ByVal OtherRGB As RGB) As Boolean
    Return (Me.R, Me.G, Me.B) = (OtherRGB.R, OtherRGB.B, OtherRGB.G)
  End Function
End Class

Module MainModule
  Sub Main()
    Dim Color As RGB = New RGB(255, 0, 0)
    Console.WriteLine(RGB.Red.IsSameColorWith(Color))
  End Sub
End Module

I can't control the equality of two tuples in IsSameColorWith(ByVal OtherRGB As RGB). How can I correct this? How can I control the equality of multiple tuples?

CodePudding user response:

I don't think you need to use tuples. Just check the equality of R, G and B:

Return Me.R = OtherRGB.R AndAlso Me.G = OtherRGB.G AndAlso Me.B = OtherRGB.B

Anyway, you can't use = operator in this case: you have to use .Equals(...).

Your code becomes:

Return (Me.R, Me.G, Me.B).Equals((OtherRGB.R, OtherRGB.B, OtherRGB.G))
  • Related