VB.Net program to return an array of integers from a user-defined function

Here, we are going to learn how to return an array of integers from a user-defined function in VB.Net?
Submitted by Nidhi, on December 14, 2020

Here, we will create a user-defined function that will return the array of integers to the calling function.

Program/Source Code:

The source code to return an array of integers from the user-defined function is given below. The given program is compiled and executed successfully.

'VB.Net program to return an array of integers 
'from a user-defined function.

Module Module1
    Function GetArray() As Integer()
        Dim arr() As Integer = New Integer(3) {1, 2, 3, 4}
        Return arr
    End Function

    Sub Main()
        Dim RetArr() As Integer

        RetArr = GetArray()

        Console.WriteLine("Elements of array:")
        For i = 0 To RetArr.Length - 1 Step 1
            Console.Write("{0} ", RetArr(i))
    End Sub
End Module


Elements of array:
1 2 3 4
Press any key to continue . . .


In the above program, we created a module Module1 that contains a user-defined function GetArray() and Main() subroutine.

The Main() subroutine is the entry point for the program. Here we created a reference for integer array.

Here we called function GetArray() that returns an array of integers, and then printed the elements of the array on the console screen.

In the GetArray() function, we created an array arr and return the array from the function.

VB.Net User-defined Functions Programs »



Comments and Discussions



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© some rights reserved.