c# - How to use array GetUpperBound

Array get upper bound
array-getupperbound.aspx

<%@ Page Language="C#" AutoEventWireup="true"%>  
  
<!DOCTYPE html>  
<script runat="server">  
    protected void Button1_Click(object sender, System.EventArgs e)  
    {
        string[,] birds = new string[6, 2]
        {
            {"Northern","Mockingbird"},
            {"Gray","Catbird"},
            {"Sage","Thrasher"},
            {"Socorro","Mockingbird"},
            {"Brown","Thrasher"},
            {"Blue","Mockingbird"}
        };

        //get index of last element of first dimension [0] in birds array.
        int rows = birds.GetUpperBound(0);

        //get index of last element of second dimension [1] in birds array.
        int columns = birds.GetUpperBound(1);

        Label1.Text = "index of last element of first dimension [0] in birds array: " + rows.ToString();
        Label1.Text += "<br />index of last element of second dimension [1] in birds array: " + columns.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 getupperbound</title>  
</head>  
<body>  
    <form id="form1" runat="server">  
    <div>  
        <h2 style="color:DarkBlue; font-style:italic;">  
            c# example - array getupperbound
        </h2>  
        <hr width="550" align="left" color="LightBlue" />    
  
        <asp:Label   
            ID="Label1"   
            runat="server"  
            Font-Size="Large"  
            >  
        </asp:Label>  
        <br />
        <asp:Button   
            ID="Button1"   
            runat="server"   
            Text="array getupperbound"  
            OnClick="Button1_Click"
            Height="40"  
            Font-Bold="true"  
            />  
    </div>  
    </form>  
</body>  
</html>
More c# examples