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.
  • 3332
 

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.

  1. Open Visual studio
     
  2. Create new website with language Vb.NET
     
  3. Now add text box and button on web form.
     

    <asp:TextBox ID="txtShowSortArray" runat="server" TextMode="MultiLine" Height="135px" Width="252px"   />&nbsp;
    <asp:Button ID="cmdSort" runat="server" Text="Sort List" Width="89px" /></div>
     

  4. Now declare the array on Default.aspx.vb page.

    Dim myArray() As String = {"Brijesh", "Pooja", "Manoj", "Neha", "Ankit"}
     

  5. 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
     

  6. 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

_output.jpg
Press the Sort list Button


_output..jpg

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.