Sorting Array Elements

 Private Sub Button1_Click(sender As System.Object, e As System.EventArgsHandles Button1.Click
        Dim result As New System.Text.StringBuilder
        Dim arrayToSort() As String = { _
           "Oranges""Apples""Grapes""Bananas""Blueberries"}

        ' ----- Show the elements before sorting.
        result.AppendLine("Before sorting:")
        For Each fruit As String In arrayToSort
            result.AppendLine(fruit)
        Next fruit

        ' ----- Show the elements after sorting.
        result.AppendLine()
        result.AppendLine("After sorting:")
        Array.Sort(arrayToSort)
        For Each fruit As String In arrayToSort
            result.AppendLine(fruit)
        Next fruit

        MsgBox(result.ToString())
    End Sub
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: