Structure Pet
Public Name As String
Public Age As Integer
End Structure
Sub OrderByEx1()
' Create an array of Pet objects.
Dim pets() As Pet = {New Pet With {.Name = "Barley", .Age = 8}, _
New Pet With {.Name = "Boots", .Age = 4}, _
New Pet With {.Name = "Whiskers", .Age = 1}}
' Order the Pet objects by their Age property.
Dim query As IEnumerable(Of Pet) = _
pets.OrderBy(Function(pet) pet.Age)
Dim output As New System.Text.StringBuilder
For Each pt As Pet In query
output.AppendLine(pt.Name & " - " & pt.Age)
Next
' Display the output.
MsgBox(output.ToString())
End Sub
沒有留言:
張貼留言