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:
... 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. ...
I would expect this 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
Would generate an output of:
5
44
but it is generating an output of:
5
55
Which to me means the ByVal for the OneDimensionalMatrix is being handled as if it was a ByRef declaration.
Am I missing something, or is this a bug in VS 2022?