c# - How to perform foreach loop through array elements

Foreach loop through an array
StringArrayForeachLoop.aspx

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

<!DOCTYPE html>

<script runat="server">

    protected void Button1_Click(object sender, System.EventArgs e)
    {
        string[] myControls = {"CheckBoxList","TreeView","FormView","Gridview"};
        Label1.Text = "Int array created successfully!";
        Label2.Text = "Array Elements:<br /><br /><i>";

        foreach (string element in myControls)
        {
            Label2.Text += element + "<br />";
        }
        Label2.Text += "</i";
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>How to get output of a string array using foreach loop in asp.net</title>
</head> 
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Green">asp.net array example:<br /> String Array and Foreach Loop</h2>
        <asp:Label 
             ID="Label1" 
             runat="server" 
             Font-Size="Large"
             ForeColor="OrangeRed"
             Font-Bold="true"
             Font-Italic="false"
             >
        </asp:Label>
        <br />
        <asp:Label 
             ID="Label2" 
             runat="server" 
             Font-Size="Large"
             ForeColor="IndianRed"
             Font-Bold="true"
             >
        </asp:Label>
        <br /><br />
        <asp:Button 
             ID="Button1" 
             runat="server" 
             OnClick="Button1_Click"
             Font-Bold="true"
             Text="Create String Array and Get Output Using Foreach Loop"
             ForeColor="DodgerBlue"
             />   
    </div>
    </form>
</body>
</html>
More c# examples