How to: Sort An Array in Visual Basic
This example declares an array of String objects named zooAnimals, populates it, and then sorts it alphabetically.
Example
Private Sub sortAnimals()
Dim zooAnimals(2) As String
zooAnimals(0) = "lion"
zooAnimals(1) = "turtle"
zooAnimals(2) = "ostrich"
Array.Sort(zooAnimals)
End Sub
Compiling the Code
This example requires:
- Access to Mscorlib.dll and the System namespace.
Robust Programming
The following conditions may cause an exception:
Array is empty (ArgumentNullException class)
Array is multidimensional (RankException class)
One or more elements of the array do not implement the IComparable interface (InvalidOperationException class)
See Also
Tasks
How to: Reverse the Contents of An Array in Visual Basic
Troubleshooting Arrays (Visual Basic)