3.5.1 array declaration and use

Source: Internet
Author: User

Before using an array, declare the array.
Syntax:
Dim array name ([expression 1 [, expression 2…]) [As data type]
You can declare one-dimensional arrays and two-dimensional arrays based on the number of expressions given. The data type is the data type of array elements. The expression is a constant. For example:
Dim a1 (10) As Integer 'declares a one-dimensional array with subscripts ranging from 0 to 10, with a total of 11 elements.
Dim a2 () As string' declares a two-dimensional array of 6 rows and 5 columns, with 30 elements in total.
You can initialize an array while declaring it. For example:
Dim arr (4) As Integer = {10, 20, 30, 40, 50}
The upper right side is called the initialization table. When the element values of the array are given in the initialization table, the size Declaration of the array in the Dim definition statement can be omitted. The preceding array declaration statement is equivalent:
Dim arr () As Integer = {10, 20, 30, 40, 50}
The reference format for elements in the array is: array name (subscript 1, subscript 2 ,......). For example:
A1 (0) = 5' assign 5 to the first element of the array
I = a1 (3) 'assigns the 4th elements of the array to I
Note: When referencing an array element, the subscript cannot exceed the declared range. For example, for Array Dim arr (4), the subscript of available array elements is 0 ~ 4.
The following code uses the For loop to set each element in the integer array to its index value.
Dim arr (5) As Integer
Dim I As Integer
For I = 0 To 5
Arr (I) = I
Next
Example 3.6: display the average table 3-14 and obtain the average score. A total of 9 students scored 90, 89, 76, 73, 100, 98, 65, 54, and 85 respectively.

Figure 3-14 shows the average score table and average score

Source code is as follows Ex3-6.aspx ):


BibliographyPrevious sectionNext section

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.