Array Reverse() Method
.Net framework Array.Reverse() method allow us to reverse the sequence of the elements in the entire one-dimensional Array.
this array Reverse() method exists under System namespace. this method require to pass a parameter named 'array'.
the 'array' parameter value type is System.Array which represents the one-dimensional Array to reverse. array Reverse() method throw ArgumentNullException, if the 'array' is null. this method also throw RankException exception, if the 'array' is multidimensional.
the following asp.net c# example code demonstrate us how can we reverse an array elements sequence programmatically at run time in an asp.net application.
the 'array' parameter value type is System.Array which represents the one-dimensional Array to reverse. array Reverse() method throw ArgumentNullException, if the 'array' is null. this method also throw RankException exception, if the 'array' is multidimensional.
the following asp.net c# example code demonstrate us how can we reverse an array elements sequence programmatically at run time in an asp.net application.
ArrayReverse.aspx
<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
private string[] favoriteColorArray = { "Green", "GreenYellow", "HoneyDew", "HotPink" };
protected void Page_Load(object sender, System.EventArgs e) {
ListBox1.DataSource = favoriteColorArray;
ListBox1.DataBind();
}
protected void Button1_Click(object sender, System.EventArgs e)
{
Array.Reverse(favoriteColorArray);
ListBox1.DataSource = favoriteColorArray;
ListBox1.DataBind();
Label1.Text = "Array reversed and repopulate ListBox";
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>How to reverse an array in asp.net</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:Green">asp.net array example: Array Reverse</h2>
<asp:Label
ID="Label1"
runat="server"
Font-Size="Large"
ForeColor="SeaGreen"
Font-Bold="true"
Font-Italic="true"
>
</asp:Label>
<br /><br />
<asp:Label
ID="Label2"
runat="server"
ForeColor="MediumVioletRed"
Font-Bold="true"
Text="The ListBox populated by an array"
>
</asp:Label>
<br />
<asp:ListBox
ID="ListBox1"
runat="server"
BackColor="MediumVioletRed"
ForeColor="AliceBlue"
>
</asp:ListBox>
<br /><br />
<asp:Button
ID="Button1"
runat="server"
OnClick="Button1_Click"
Font-Bold="true"
Text="Reverse Array And RePopulate ListBox"
ForeColor="MediumVioletRed"
/>
</div>
</form>
</body>
</html>


- How to clear an array
- How to sort an array elements
- How to initialize an int array
- How to convert a string array to a list
- How to convert a string to a byte array
- How to sort array elements in descending order
- How to copy elements in one array to another array
- How to check if a string array contains a value
- How to check string contains a string in string array
- How to check char array contains a char