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>

- How to initialize a two dimensional array
- How to initialize a two dimensional int array
- How to perform for loop through a two dimensional array elements
- How to copy elements in one array to another array
- How to check if a string array contains a value
- How to convert a string array to a double array
- How to convert a string array to an int array
- How to get distinct values from an array
- How to get dimension length of an array
- How to get difference between two arrays