Runing Text

Do not Click

Array

Sunday 23 August 2009 , Posted by Andi at 01:18


Array can be interpreted as a sequence of data which is so easy to referenced. Variable used hrus directly referenced using the variable, it will be difficult if there is a lot of data to be processed simultaneously. For example:

Dim a, b, c, d, e as integer
...
Console.writeline (a)
Console.writeline (b)
Console.writeline (c)
Console.writeline (d)
Console.writeline (e)


To display all of variables are necessary because the 5 statements each variable must be mentioned directly. By using the array, the repetition of these constraints can be overcome by using the help of the loop. Array declaration syntax is:

Dim var_name (length) [as data_type]


Or


Dim var_name ()


The first way is used to produce arrays with a fixed element, while the latter will result in an array without a fixed length.

Example:

Myadd Dim as string = "192.168.1.31"
Dim result () as string = myadd.split


Or

Dim result (6) as string = myadd.spilt


By using the dynamic long array elements can be changed when the program starts by using redIm, but its elements will be reset again. To maintain the value of these arrays can be used redIm Preserve.
Example:

RedIm Result (10)
Preserve redIm Result (10)


By default, the array index starts pada.net 0 to length index. So the length of 5 will result in 6 elements (0,1,2,3,4,5). Next arrays can be used directly by accessing its index.
Example:

Dim i (5) as integer
...
Console.writeline (i (0))
Console.writeline (i (1))
Console.writeline (i (2))
Console.writeline (i (3))
Console.writeline (i (4))
Console.writeline (i (5))


For each Clause
For each loop is one that can be used di.Net, However the only useful to use arrays and collection scope. For each clause will make the loop as many elements of the array or collection without the need to specifically mention the specific length, and requires a variable with the type of data in accordance with the elements in the array or collection. Sintaxnya are:
For each var_name [as data_type] in array_name
Next
Example

Dim myarr () as Integer = (1,2,3,4)
For each element as Integer in myarr
Console.writeline (element)
Next

Currently have 0 komentar:

Leave a Reply

Post a Comment

Related Post