Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim M(5) As Test
M(0) = New Test(5)
M(1) = New Test(10)
M(2) = New Test(2)
M(3) = New Test(21)
M(4) = New Test(4)
M(5) = New Test(18)
Array.Sort(M)
Me.ListBox1.DataSource = M
Me.ListBox1.DisplayMember = "M"
End Sub
Public Class Test
Implements IComparable
Private _M As Integer
Sub New(ByVal m As Integer)
Me._M = m
End Sub
Public ReadOnly Property M() As Integer
Get
Return _M
End Get
End Property
Public Function CompareTo(ByVal obj As Object) As Integer Implements System.IComparable.CompareTo
If TypeOf obj Is Test Then
Dim temp As Test = CType(obj, Test)
Return _M.CompareTo(temp._M)
End If
Throw New ArgumentException("object is not a Test!")
End Function
End Class