Creating Array in Visual Basic .NET

In this lesson I am going to create simple array to hold the days of the week
I need string array and I need seven elements to hold days
So I can define the array

I have put 6 instead of 7.
why?
Numbering start at zero, although you put 6 there it has 7 elments

Now we will assign days for each elements

Now I need to iterate through all elements through the array. I can use either For…Next loop or For…Each Next loop
I will use For…Each Next loop first

Output

 


This is the other method of iterating the array. It is For…Next method

Initializing arrays with Values
You can initialize the array when you define it . It can be done in single line of code

You do not have to define the upper bound of the array. You can leave it with empty parentheses

Leave a Reply

Your email address will not be published. Required fields are marked *