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:Label ID="Label1" runat="server" Text="List of Unsorted name"></asp:Label>

    <br />

    <br />

    <asp:TextBox ID="TextBox1" runat="server" Height="175px" TextMode="MultiLine"

    Width="200px"></asp:TextBox>

    <br />

    <br />

    <asp:Button ID="Button1" runat="server" onclick="Button1_Click"

    Text="Sorted list" />

    <br />

    <br />

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

    {

    string[] myArray = {

    "Brijesh",

    "Pooja",

    "Manoj",

    "Neha",

    "Ankit"

    };

  5. Now write the following code on page load event

    //Message Displayed on your WebForm

    Label1.Text = "Unsorted Array List";

    //Displays UnSorted list

    foreach (string arrayStr in myArray)

    {

    TextBox1.Text += arrayStr + Constants.vbCrLf;

    }

  6. Now use the following code on button cliick.

    //Method that Sort the List

    Array.Sort(myArray);

    //Sets the Text to Null

    TextBox1.Text = string.Empty;

    //Displays the Sorted list

    Label1.Text = "Sorted Array List";

    foreach (string arrayStr in myArray)

    {

    TextBox1.Text += arrayStr + Constants.vbCrLf;

    }

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