VB.Net

VB.Net Arrays

VB.Net Arrays

An array stores a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type.

All arrays consist of contiguous memory locations. The lowest address corresponds to the first element, and the highest address to the last element.


Arrays in VB.Net

Creating Arrays in VB.Net

To declare an array in VB.Net, you use the Dim statement. You can also initialize the array elements while declaring the array. The elements in an array can be stored and accessed by using the index of the array. 

Dynamic Arrays

Dynamic arrays are arrays that can be dimensioned and re-dimensioned as the program requires. The ReDim statement can be used to declare a dynamic array.

The syntax for ReDim statement −

ReDim [Preserve] arrayname(subscripts)

Where,

  • The Preserve keyword aids in the preservation of data in an existing array when it is resized.
  • arrayname is the name of the array that will be re-dimensioned.

Multi-Dimensional Arrays

Multidimensional arrays are supported by VB.Net. Rectangular arrays are another name for multidimensional arrays.

Jagged Array

A Jagged array is a collection of arrays. The code below explains how to declare a jagged array called scores of Integers.

Dim scores As Integer()() = New Integer(5)(){}

The Array Class

The Array class is the foundation for all arrays in VB.Net. It is specified in the namespace System. The Array class contains several attributes and methods for working with arrays.

Please see Microsoft documentation for a complete list of Array class properties and methods.

Top course recommendations for you

    Create a IPL theme Landing page with CSS and HTML
    1 hrs
    Beginner
    7K+ Learners
    4.3  (331)
    PyTest Basics
    2 hrs
    Beginner
    2.8K+ Learners
    4.44  (149)
    Python MySQL
    1 hrs
    Beginner
    12.4K+ Learners
    4.46  (602)
    Python Automation Project
    2 hrs
    Beginner
    7.1K+ Learners
    4.58  (248)
    Python For Android
    2 hrs
    Beginner
    5.5K+ Learners
    4.49  (148)
    Kivy Projects
    2 hrs
    Beginner
    1.9K+ Learners
    4.49  (57)
    Regex in Python
    1 hrs
    Beginner
    2.9K+ Learners
    4.52  (321)
    Heap Sort Program in C
    1 hrs
    Beginner
    1.3K+ Learners
    4.48  (42)