How to write a user defined function for dynamic parameter passing

Asked By 0 points N/A Posted on -
qa-featured

Hi!

Can anyone kindly help me to write a function for dynamic parameter passing in VB.Net and also state the limit of the parameters in such case?

 

SHARE
Best Answer by kelles201
Best Answer
Best Answer
Answered By 0 points N/A #119647

How to write a user defined function for dynamic parameter passing

qa-featured

Hi Mudazarr!

I carried out some research about your issue and I've got a solution for you. Here are the samples you need:

Imports System

  • Public Class MainClass
  • Shared Sub Main()

Dim A() As String = {"HELLO", "GOODBYE"} Console.WriteLine("Original first item in array is: " _ & A(0))
        Console.WriteLine("Original second item in array is: " _& A(1))
        AFunction(A)
        Console.WriteLine("After passing by value first item in array now is: " _ & A(0))
        Console.WriteLine("After passing by value second item in array is: " _ & A(1))

End Sub

       Shared Sub AFunction(ByVal Foo As String())
       Foo(0) = "GOODBYE"
       Foo(1) = "HELLO"

End Sub

End Class

  • I also did read that parameter limits are 2100 and am quite sure about it.

Hope this will work!

Thanks.

Answered By 0 points N/A #119648

How to write a user defined function for dynamic parameter passing

qa-featured

These types of functions are called Variadic function,   which means that such functions can be called by passing 0 or more parameters. 

The following is a VB.NET Example:

Public Shared Sub PrintSpaced(ParamArray objects As Object())

For Each o As Object In objects

Console.Write(o & " ")

Next

End Sub

 

Login/Register to Answer

Related Questions