Sorting an array - .Net Views : 267
Tagged in : .Net
0 0
Send mail
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
By banumathi, On - 2011-03-15



    Login to add Comments .