Ad space (banner)
๐Ÿ”ทVB.NET Lessons
Lesson 7 / 68

Working with arrays

This lesson covers the basics of arrays in VB.NET, with the aim of handling several pieces of data together.

An array is like a shelf of numbered drawers. { } supplies its initial values all at once. Gathering several values into one array, rather than into separate variables, lets you handle them efficiently with a loop.

The sample code declares an array as Dim fruits() As String = {"apple", "orange", "grape"} and displays each element with a number using a For statement. Note fruits.Length, which gives the number of elements.

A common early stumble is reaching past the end of an array, which is an error. The loop range needs care — typically fruits.Length - 1.

An array's size is fixed at declaration; when you need the length to change, List(Of T) is the usual choice. Choosing between the two as the situation demands matters in real code design.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run VB.NET directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)