Asp.net Array (Array) can be considered as a variable that stores multiple values of the same data type. Multiple values are distinguished by the same variable name and different index values. It is used to store data of the same nature or type.
1. array declaration
The declaration of arrays can be in the following two formats:
The following is a reference clip:
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 an array is declared and its elements are assigned, the array can be executed. The element expression of the array is as follows:
Array name (index value) = element value
Tip: the index value is calculated from O. You can declare a maximum of 264 elements (the Long type ).
3. Example
Compile an ASP program and use the array to create a webpage.
Display the date of the current day.
Program code:
The following is a reference clip:
<Html>
<Hr>
<%
Dim cw (7)
Cw (O) = "Sunday ".
Cw (1) = "Monday"
Cw (2) = "Tuesday"
Cw (3) = "Wednesday"
Cw (4) = "Thursday"
Cw (5) = "Friday"
Cw (6) = "Saturday"
Response. write (today is? & yea r (now () & "")
Response. write (month (now () & "month" & day (now () & "day ")
Response. write (cw (Wee kDay (now () 1 ))
%>
<Hr>
</Html>
The procedure is described as follows:
Lines 5 from 3rd to 1: the entity of the ASP program.
Row 4th: declares an array CW, with seven elements in the array.
5th ~ Row 11: defines each element in the array. The data type is a string.
Row 12-14: the date and time functions and arrays are used to output the data using the write method of the response object. In row l, the data is replaced by the WeekDay function. the A, now () function is used to obtain the week value. The value range is 1 ~ 7. Because the index value in the array is to be substituted into the index value, and the index value in the array is calculated from O, 1 is required in this output program, and the calculated week value range is set to O ~ 6, to match the index value of the array, to bring out the string represented by each index value.