Sorting an array

by banumathi 2011-03-15 17:56:49

Arrays that consist of elements that implement the IComparable interface can be sorted using the Sort() method via the following syntax: Array.Sort(ArrayName)


Example:


Sub Page_Load(sender as Object, e as EventArgs)
Dim randNumbers(10) as Integer
Dim i as Integer
Dim rndNum as New Random()

For i = 0 to 10
randNumbers(i) = rndNum.Next(100)
Next i

' Display the random numbers
randNumDisplay.DataSource = randNumbers
randNumDisplay.DataBind()

' Sort the array
Array.Sort(randNumbers)

' Display the sorted array
orderedNumDisplay.DataSource = randNumbers
orderedNumDisplay.DataBind()
End Sub

Tagged in:

1106
like
0
dislike
0
mail
flag

You must LOGIN to add comments