c# - How to perform for loop through a two dimensional array elements

For loop through two dimensional array
TwoDimensionStringArrayOutput.aspx

<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">

    protected void Button1_Click(object sender, System.EventArgs e)
    {
        string[,] colors = { { "Beige", "#F5F5DC" }, { "Bisque", "#FFE4C4" }, { "BlueViolet", "#8A2BE2" }, { "Brown", "#A52A2A" }, { "BurlyWood", "#DEB887" } };
        Label1.Text = "Two dimensional String array created successfully!<br />Output Of Array elements:<br /><br /><i>";
        int rows = colors.GetUpperBound(0);
        int columns = colors.GetUpperBound(1);
        Label2.Text = "";

        for (int currentRow = 0; currentRow <= rows; currentRow++)
        {
            for (int currentColumn = 0; currentColumn <= columns; currentColumn++)
            {
                Label2.Text += colors[currentRow, currentColumn];
                Label2.Text += " ";
            }
            Label2.Text += "<br />";
        }
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>How to get output of a two dimension string array in asp.net</title>
</head> 
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Teal">asp.net array example:<br />Two Dimension String Array Output</h2>
        <asp:Label 
             ID="Label1" 
             runat="server" 
             Font-Size="Large"
             ForeColor="OrangeRed"
             Font-Bold="true"
             Font-Italic="true"
             >
        </asp:Label>
        <br />
        <asp:Label 
             ID="Label2" 
             runat="server" 
             Font-Size="Large"
             ForeColor="SaddleBrown"
             Font-Bold="true"
             Font-Italic="true"
             >
        </asp:Label>
        <br /><br />
        <asp:Button 
             ID="Button1" 
             runat="server" 
             OnClick="Button1_Click"
             Font-Bold="true"
             Text="Create Two Dimensional String Array And Show Output"
             ForeColor="DodgerBlue"
             />   
    </div>
    </form>
</body>
</html>
More c# examples