Array get length
.Net framework Array.Length property allow us to get a 32-bit integer that represents the total number of elements
in all the dimension of the Array. this array Length property exists in System namespace.
the array Length property return value data type is System.int32. this integer value represents the total number of elements in all the dimension of the array. this property return zero, if there are no elements exists in the array.
array Length property throw OverFlowException exception, if the array is multidimensional and contains more than MaxValue elements. MaxValue represents the largest possible value of an Int32. this field is constant.
the following asp.net c# example code demonstrate us how can we get an array length programmatically at run time in an asp.net application.
the array Length property return value data type is System.int32. this integer value represents the total number of elements in all the dimension of the array. this property return zero, if there are no elements exists in the array.
array Length property throw OverFlowException exception, if the array is multidimensional and contains more than MaxValue elements. MaxValue represents the largest possible value of an Int32. this field is constant.
the following asp.net c# example code demonstrate us how can we get an array length programmatically at run time in an asp.net application.
array-getlength.aspx
<%@ Page Language="C#" AutoEventWireup="true"%>
<!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
string[,] birds = new string[5, 2]
{
{"Pygmy","Swift"},
{"Collared","Inca"},
{"Frilled","Coquette"},
{"Ecuadorian","Hillstar"},
{"Greenish","Puffleg"}
};
int rows = birds.GetUpperBound(0);
int columns = birds.GetUpperBound(1);
//get number of elements exists in first dimension
int firstDimensionLength = birds.GetLength(0);
//get number of elements exists in second dimension
int secondDimensionLength = birds.GetLength(1);
Label1.Text = "first dimension[0] length: " + firstDimensionLength.ToString();
Label1.Text += "<br />second dimension[1] length: " + secondDimensionLength.ToString();
Label1.Text += "<br /><br />two dimension birds array elements.........<br />";
for (int currentRow = 0; currentRow <= rows;currentRow++ )
{
for (int currentColumn = 0; currentColumn <= columns;currentColumn++ )
{
Label1.Text += birds[currentRow, currentColumn] + " ";
}
Label1.Text += "<br />";
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>c# example - array getlength</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:DarkBlue; font-style:italic;">
c# example - array getlength
</h2>
<hr width="550" align="left" color="LightBlue" />
<asp:Label
ID="Label1"
runat="server"
Font-Size="X-Large"
>
</asp:Label>
<br />
<asp:Button
ID="Button1"
runat="server"
Text="array getlength"
OnClick="Button1_Click"
Height="40"
Font-Bold="true"
/>
</div>
</form>
</body>
</html>

- How to initialize a string array
- How to convert a decimal array to a string
- How to convert a decimal array to a string array
- How to perform for loop through an array elements
- How to fill an array with a single value
- How to find index of an element from an array that match the conditions
- Find index of last element from an array that match the conditions
- How to filter an array elements
- How to get the rank of an array
- How to remove the first element from an array