Search

Sunday, March 23, 2014
0 comments

Reverse array item example in c#

10:57 PMSunday, March 23, 2014
Sorting means ," arranging items of array either in ascending or descending order, known as sorting. Here this example display reverse order of any array items. If you take string type then use Reverse method of Array.

Source code in ASP.NET

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button"
        Width="100px" />
    <div style="width: 180px">
   
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
   
    </div>
    </form>
</body>
</html>

Code behind code

    protected void Button1_Click(object sender, EventArgs e)  
    {
        string[] fruits = new string[]
        {
            "Red Apple",
            "Yellow Papaya",
            "Orang Orange"
        };

        int[] numbers = new int[] { 65,105,640,800};

        Label1.Text = " fruits array elements.........<br />";
        for (int j = 0; j < fruits.Length; j++)
        {
            Label1.Text += fruits[j] + "<br />";
        }

        Array.Reverse(fruits);
        Label1.Text += "<br /> fruits array elements [after reverse array elements].........<br />";
        for (int j = 0; j < fruits.Length; j++)
        {
            Label1.Text += fruits[j] + "<br />";
        }

        Label1.Text += "<br />numbers array elements.........<br />";
        for (int j = 0; j < numbers.Length; j++)
        {
            Label1.Text += numbers[j].ToString() + "<br />";
        }

        Array.Reverse(numbers);
        Label1.Text += "<br />numbers array elements [after reverse array elements].........<br />";
        for (int j = 0; j < numbers.Length; j++)
        {
            Label1.Text += numbers[j].ToString() + "<br />";
        }
    }  
 

Reverse array item example in c#

Protected by Copyscape Online Copyright Protection Software

0 comments :

Post a Comment

 
Toggle Footer
Top