שתף באמצעות


How to pass an array as an optional argument

Question

Thursday, November 17, 2005 12:36 AM

Hi,

I would like to pass a multi-dimensional array as an optional argument to a procedure.  The trouble is I'm having difficulty trying to assign the array to a default value.  Can anyone help?!

Jo

All replies (3)

Thursday, November 17, 2005 7:06 AM ✅Answered

You can't initialize a multi-dimensional array inline with the function/sub declaration as it needs to be a constant expression, instead try something like the following:


Public Sub MyMethod(Optional ByVal array(,) As Short = Nothing)


    If (array Is Nothing) Then
        array = New Short(1, 1) {{10, 10}, {10, 10}}
    End If

End Sub


 


Thursday, November 17, 2005 1:58 AM

Let's consider the following:

(ByVal A As String , Optional ByVal Filespec As String = Nothing)

It doesn't make any difference if you say...

(ByVal A As String , Optional ByVal B As system.array = Nothing)

:)


Thursday, November 17, 2005 3:06 PM

Thanks!  That was very helpful.