Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim people As New List(Of Person)
people.Add(New Person With {.FirstName = "Mary", .LastName = "Smith"})
people.Add(New Person With {.FirstName = "John", .LastName = "Smith"})
people.Add(New Person With {.FirstName = "Bill", .LastName = "Jones"})
people.Sort(AddressOf ComparePeopleByLastNameThenFirstName)
For Each person In people
MessageBox.Show(person.FirstName, person.LastName)
Next
End Sub
Private [COLOR="#FF0000"]Function[/COLOR] ComparePeopleByLastNameThenFirstName([COLOR="#FF0000"]person1[/COLOR] As Person, [COLOR="#FF0000"]person2[/COLOR] As Person) As Integer
Return [COLOR="#FF0000"]person1.LastName.CompareTo(person2.LastName)[/COLOR]
End Function
End Class
Public Class Person
Public Property FirstName As String
Public Property LastName As String
End Class
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim people As New List(Of Person)
people.Add(New Person With {.FirstName = "Mary", .LastName = "Smith"})
people.Add(New Person With {.FirstName = "John", .LastName = "Smith"})
people.Add(New Person With {.FirstName = "Bill", .LastName = "Jones"})
people.Sort([COLOR="#FF0000"]Function[/COLOR]([COLOR="#FF0000"]person1[/COLOR], [COLOR="#FF0000"]person2[/COLOR]) [COLOR="#FF0000"]person1.LastName.CompareTo(person2.LastName)[/COLOR])
For Each person In people
MessageBox.Show(person.FirstName, person.LastName)
Next
End Sub
End Class
Public Class Person
Public Property FirstName As String
Public Property LastName As String
End Class