VB.net Program to Pass an Array Into User Define the Function

You are currently viewing VB.net Program to Pass an Array Into User Define the Function

VB.Net program to pass an array into user define the function

'VB.Net program to pass an array into user-defined function.

Module Module1
    Function AddNum(ByVal arr() As Integer) As Integer
        Dim result As Integer = 0

        For i = 0 To arr.Length - 1 Step 1
            result = result + arr(i)
        Next

        AddNum = result
    End Function

    Sub Main()
        Dim result As Integer = 0
        Dim arr() As Integer = New Integer(5) {1, 2, 3, 4, 5, 6}

        result = AddNum(arr)

        Console.WriteLine("Sum is: {0}", result)
    End Sub
    
End Module
Sum is: 21
Press any key to continue . . .

Ranjith Kumar

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply