O'Reilly logo

VB.NET Language in a Nutshell, Second Edition by Steven Roman PhD, Paul Lomax, Ron Petrusha

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

Array.Sort Method

Class

System.Array

Syntax

Array.Sort(array)
Array.Sort(array, comparer)
Array.Sort(array, index, length)
Array.Sort(array, index, length, comparer)

Array.Sort(keys, items)
Array.Sort(keys, items, comparer)
Array.Sort(keys, items, index, length)
Array.Sort(keys, items, index, length, comparer)
array (required; any array)

The array of objects to be sorted.

keys (required; any array)

The array of keys to use for sorting. This array is also sorted.

items (required; any array)

A parallel array of values to be sorted in the order of keys, their corresponding keys.

index (required; Integer)

The index at which to start the sort.

length (required; Integer)

The index at which to end the reversal process.

comparer (required; IComparer interface)

An object implementing the IComparer interface to be used for sorting. If Nothing, then the IComparable implementation of each element (in the case of arrays of keys) or value type (in the case of arrays).

Return Value

None

Description

Sorts a portion of, or sorts an entire one-dimensional array, with an optionally specified key array and an optionally specified IComparer interface

Example

Sub sortArray(  )
Dim i As Integer
Dim intArray(  ) As Integer = {9, 8, 12, 4, 5}
For i = 0 To 4
    console.WriteLine(CStr(intArray(i)))
Next
System.Array.Sort(intarray)
Console.WriteLine("Sorted:")
For i = 0 To 4
    console.WriteLine(CStr(intArray(i)))
Next
End Sub

The output is:

9
8
12
4
5
Sorted:
4
5
8
9
12

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required