VB.Net program to demonstrate the Resize() method of Array class

Here, we are going to demonstrate the Resize() method of Array class in VB.Net.
Submitted by Nidhi, on January 20, 2021 [Last updated : March 07, 2023]

Array.Resize() Method in VB.Net

The Resize() method is used to change the size of the specified array.

Syntax

Sub Resize(ByVal arr() as object, ByVal newsize as integer)

Parameter(s)

  • Arr: It is the specified integer array to be resized.
  • newsize: Specified new size.

Return Value

It does not return any value.

VB.Net code to demonstrate the example of Array.Resize() method

The source code to demonstrate the Resize() method of the Array class is given below. The given program is compiled and executed successfully.

'VB.NET program to demonstrate the Resize() 
'method of Array class.

Imports System

Module Module1
    Sub Main()
        Dim arr() As Integer = {10, 20, 30, 40, 50}

        Array.Resize(arr, 10)

        arr(5) = 60
        arr(6) = 70
        arr(7) = 80
        arr(8) = 90
        arr(9) = 100

        Console.WriteLine("Array elements: ")
        For i = 0 To arr.Length - 1 Step 1
            Console.Write(arr(i) & " ")
        Next
        Console.WriteLine()
    End Sub
End Module

Output

Array elements:
10 20 30 40 50 60 70 80 90 100
Press any key to continue . . .

Explanation

In the above program, we created a module Module1 that contains the Main() function. The Main() function is the entry point for the program.

In the Main() function, we created an array arr with 5 elements. After that we resize the array using Resize() method and then we assigned more elements to the array and print all array elements on the console screen.

VB.Net Array Programs »






Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.