VB.NET:
Class Murid
Implements IComparable
Public strNama, strKelas As String
Public Function CompareTo(ByVal obj As Object) As Integer _
Implements System.IComparable.CompareTo
Dim Compare As Murid = CType(obj, Murid)
Dim result As Integer = Me.strKelas.CompareTo(Compare.strKelas)
Return result
End Function
End Class
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ara As New ArrayList
Dim murid As New Murid
murid.strNama = "Philip"
murid.strKelas = "2"
ara.Add(murid)
murid = New Murid
murid.strNama = "Vivi"
murid.strKelas = "1"
ara.Add(murid)
For Each murid In ara
MsgBox(murid.strNama)
Next
ara.Sort()
For Each murid In ara
MsgBox(murid.strNama)
Next
End Sub
please someone help me explain how this code work ? i try it and it work finely, but still i dont know how it working.
thanks,
Last edited by a moderator: