How to write a user defined function for dynamic parameter passing
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?
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?
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
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
Hope this will work!
Thanks.
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