Initializing two dimensional array
TwoDimensionStringArray.aspx
<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
string[,] colorArray = { { "AliceBlue", "#F0F8FF" }, { "AntiqueWhite", "#FAEBD7" }, { "Aqua", "#00FFFF" }, { "Azure", "#F0FFFF" } };
Label1.Text = "Two dimensional String array created successfully!<br />Array elements:<br /><br /><i>";
int rows = colorArray.GetUpperBound(0);
int columns = colorArray.GetUpperBound(1);
Label2.Text = "";
for (int currentRow = 0; currentRow <= rows; currentRow++)
{
for (int currentColumn = 0; currentColumn <= columns; currentColumn++)
{
Label2.Text += colorArray[currentRow, currentColumn];
Label2.Text += " ";
}
Label2.Text += "<br />";
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>How to create two dimension string array in asp.net</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:Navy">asp.net array example: Two Dimension String Array</h2>
<asp:Label
ID="Label1"
runat="server"
Font-Size="Large"
ForeColor="HotPink"
Font-Bold="true"
Font-Italic="true"
>
</asp:Label>
<br />
<asp:Label
ID="Label2"
runat="server"
Font-Size="Large"
ForeColor="SeaGreen"
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"
ForeColor="DarkBlue"
/>
</div>
</form>
</body>
</html>

- How to perform foreach loop through array elements
- 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 perform binary search on an array
- How to create an array of objects
- How to fill an array with a single value
- How to get the first element of an array
- How to get the last element of an array