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
    5.9K+ Learners
    4.29  (243)
    PyTest Basics
    2 hrs
    Beginner
    2.3K+ Learners
    4.35  (101)
    Python MySQL
    1 hrs
    Beginner
    9K+ Learners
    4.52  (299)
    Python Automation Project
    2 hrs
    Beginner
    5.8K+ Learners
    4.56  (152)
    Python For Android
    2 hrs
    Beginner
    4.4K+ Learners
    4.48  (83)
    Kivy Projects
    2 hrs
    Beginner
    1.6K+ Learners
    4.51  (39)
    File Manipulation in Python
    1 hrs
    Beginner
    1.3K+ Learners
    4.22  (37)
    Regex in Python
    1 hrs
    Beginner
    2.1K+ Learners
    4.31  (87)
    Heap Sort Program in C
    1 hrs
    Beginner
    1.1K+ Learners
    4.56  (32)
    Python Jobs
    2 hrs
    Beginner
    2.4K+ Learners
    4.52  (50)