Asp.net array (Array) can be regarded as a variable that stores multiple values of the same data type. The same variable name and different index values are used to distinguish and represent multiple values. It is mostly used to store data of the same nature or type.
1. Array declaration
There are two formats for array declaration:
The following is a reference fragment:
Dim array name (number of elements) [As data type]
Dim array name () [As data type] = {element value l, element value 2...}
2. Representation of array elements
After declaring an array and assigning elements to it, the array can begin execution. The elements of the array are represented as follows:
array name (index value) = element value
Tip: The index value is calculated starting from O. The maximum number of array elements can be declared is 264 to 1 (i.e. Long type).
3. As an example
, write an ASP program that uses arrays to create the function of displaying the current date after entering the web page
.
Program code:
The following is a quoted fragment:
01<html>
02<hr>
03 <%
04 Dim cw(7)
05 cw(O)=¨Sunday".
06 cw(1)=¨Monday”
07 cw(2)="Tuesday"
08 cw(3)=¨Wednesday”
09 cw(4)=¨Thursday¨
10 cw(5)=¨Friday”
11 cw(6)=¨Saturday¨
1 2 response. write(¨Today is¨&yea r(now())&"year")
13 response. write(month(now()) & "month" &day(now()) & "day")
14 response. write(cw(Wee kDay(now())-1))
l5%>
1 6<hr>
l7</html>
The description of this program is as follows
· Line 3-1 5: is the main body of the ASP program.
· Line 4: Declare an array CW with 7 elements in the array.
· Lines 5 to 11: Define each element in the array, and the data type is string.
· Lines 1, 2-1, 4: Use the date and time function and array to output the date using the write method of the response object. In line 1, 4, the WeekDay function is used instead. A, now() function is used to find the day of the week value. The value range is from 1 to 7, because the index value in the array needs to be substituted, and the index value in the array is calculated from O, so in this output program, 1 must be subtracted, and the calculated week value range should be set between O and 6. Matches the index values of the array to bring out the string represented by each index value.