Net-informations.com
SiteMap  | About    

ASP.NET Array

Arrays are using for store similar data types grouping as a single unit. We can access Array elements by its numeric index. The array indexes start at zero.

The default value of numeric array elements are set to zero, and reference elements are set to null .

vb.net
  Dim arr(6) As String
  arr(0) = "Sunday"

arr(1) = "Monday"

C#
  string[] arr = new string[7];
  arr[0] = "Sunday";

arr[1] = "Monday";

The abovecode declare a string array of 7 strings and assign some values to it.

We can access the Arrays elements by providing its numerical index.

vb.net

  Dim str As String = arr(1)

C#

  string str = arr[1];

Above statement returns the second value from the Array.

The following ASP.NET program fill an arra with seven days in a week and bind it to a ListBox control.

Default.aspx

  

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
	<title>Untitled Page</title>
</head>
<body>
	<form id="form1" runat="server">
	<div>
		<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
		<br />
		<asp:ListBox ID="ListBox1" runat="server"></asp:ListBox><br />
	</div>
	</form>
</body>
</html>


Click the following links to see full source code

C# Source Code
VB.NET Source Code
Default.aspx.cs
Default.aspx.vb





net-informations.com (C) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.