Sub / Function array parameter altered

后端 未结 4 1840
一整个雨季
一整个雨季 2021-01-22 19:14

I have a Sub with an array of strings as parameter:

Private Sub des(ByVal array() As String)

    Dim i As Integer

    For i = 0 To UBound(array)
        array(         


        
4条回答
  •  我在风中等你
    2021-01-22 20:02

    I read on a site that you cannot pass arrays ByVal. Is this true?

    No, that is not true.

    An array in the .NET framework is a reference type. When you create an array, an object of System.Array will be created and its reference is assigned to the reference variable.

    When you call a des method, the reference of the array object will be passed. In des method, ByVal parameter is a reference parameter variable of type System.Array, and it receive a copy of reference of an array object.

    MSDN article - Passing Arguments by Value and by Reference (Visual Basic)

提交回复
热议问题