How to: sort an array in Visual Basic

This article shows an example of how to sort an array of strings in Visual Basic.

Example

This example declares an array of String objects named zooAnimals, populates it, and then sorts it alphabetically:

Private Sub SortAnimals()
    Dim zooAnimals(2) As String
    zooAnimals(0) = "lion"
    zooAnimals(1) = "turtle"
    zooAnimals(2) = "ostrich"
    Array.Sort(zooAnimals)
End Sub

Robust programming

The following conditions may cause an exception:

See also