Use Array and String in Vb.NET to Sort Method
In this article we will learn how to use array and string in VB.NET.
In this article we learn How to sort string Using array. It is more important project related to array. In this we can also learn how to use array.
- Open Visual studio
- Create new website with language Vb.NET
-
Now add text box and button on web form.
<asp:TextBox ID="txtShowSortArray" runat="server" TextMode="MultiLine" Height="135px" Width="252px" />
<asp:Button ID="cmdSort" runat="server" Text="Sort List" Width="89px" /></div>
-
Now declare the array on Default.aspx.vb page.
Dim myArray() As String = {"Brijesh", "Pooja", "Manoj", "Neha", "Ankit"}
-
Now write the following code on page load event
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me. Load
'Message Displayed on your WebForm
lblShowMsg.Text = "Unsorted Array List"
Displays UnSorted list
For Each arrayStr As String In myArray
txtShowSortArray.Text += arrayStr & vbCrLf
Next
End Sub
-
Now use the following code on button cliick.
Protected Sub cmdSort_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdSort.Click
'Method that Sort the List
Array.Sort(myArray)
'Sets the Text to Null
txtShowSortArray.Text = String.Empty
'Displays the Sorted list
lblShowMsg.Text = "Sorted Array List"
For Each arrayStr As String In myArray
txtShowSortArray.Text += arrayStr & vbCrLf
Next
End Sub
Now run this application and you get a sorted result.
End of this application.
Output of This Application

Press the Sort list Button