Module Module1
Sub Main()
Dim strings As ip() = {New ip(2), New ip(1), New ip(4), New ip(3), New ip(5)}
Array.Sort(Of ip)((strings), New Comparison(Of ip)(AddressOf CompareStringsDescending))
'this previous sort, does it mean
'Array.Sort(only sort ip class)(( sort strings object), the rest properties what does it mean ?)
'Array.Sort(strings)
For Each ip As ip In strings
Console.WriteLine(ip.angka)
Next
Console.ReadLine()
End Sub
Class ip
Implements IComparable
Public angka As Integer
Sub New(ByVal int As Integer)
angka = int
End Sub
Public Function CompareTo(ByVal obj As Object) As Integer Implements IComparable.CompareTo
If Me.angka > CType(obj, ip).angka Then
Return 1
ElseIf Me.angka = CType(obj, ip).angka Then
Return 0
Else
Return -1
End If
End Function
End Class
Private Function CompareStringsDescending(Of ip)(ByVal x As ip, ByVal y As ip) As Integer '<-- what function (of ip) on here ?
Return y.CompareTo(x) ' why not working ? i just learned implement comparable
'Return y.
End Function
End Module