title: ByVal behaving like ByRef
body: <p>Perhaps this is a bug in the (current version of) Visual Studio 2022 ...
  but according to everything I had understood about ByVal vs ByRef up until now, as well as this doc:</p>
  <p><a href="https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/procedures/passing-arguments-by-value-and-by-reference#:%7E:text=The%20advantage%20of%20passing%20an,being%20changed%20by%20the%20procedure" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/procedures/passing-arguments-by-value-and-by-reference#:~:text=The%20advantage%20of%20passing%20an,being%20changed%20by%20the%20procedure</a>.</p>
  <blockquote>
  <p>... If the underlying element is modifiable, but you do not want the procedure to be able to change its value, declare the parameter ByVal. Only the calling code can change the value of a modifiable element passed by value. ...</p>
  </blockquote>
  <p>I would expect this code:</p>
  <pre><code>Friend Sub Driver()
  
      Dim index As Integer = 5
  
      Dim OneDimensionalMatrix(index) As Integer
  
      For x As Integer = 0 To index - 1
          OneDimensionalMatrix(x) = 44
      Next
  
      SubRoutine(index, OneDimensionalMatrix)
  
      Console.WriteLine(index)
  
      Console.WriteLine(OneDimensionalMatrix(3))
  
  End Sub
  
  Public Sub SubRoutine(ByVal matrixSize As Integer, ByVal OneDimensionalMatrix() As Integer)
  
      For x As Integer = 0 To matrixSize - 1
  
          OneDimensionalMatrix(x) = 55
  
      Next
  
      matrixSize = 100
  
  End Sub
  </code></pre>
  <p>Would generate an output of:</p>
  <p>5</p>
  <p>44</p>
  <p>but it is generating an output of:</p>
  <p>5</p>
  <p>55</p>
  <p>Which to me means the ByVal for the OneDimensionalMatrix is being handled as if it was a ByRef declaration.</p>
  <p>Am I missing something, or is this a bug in VS 2022?</p>