I am familiar with the difference between ByVal and ByRef.
However, I was confused why I could pass a WinForms control to a sub using ByVal in order to change some of its properties. In a lot of articles "ByVal" is used, and I was confused about that. I was especially confused when the sub actually did change the control's properties. I was wondering how that could be possible when "ByVal" is used. In my understanding, a sub shouldn't be able to manipulate a control if it's passed ByVal.
To test this a little further, I ran the following test code:
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim n As New List(Of String)
n.Add("test0")
pAlterList(n)
Debug.Assert(n(0) = "test0")
End Sub
Private Sub pAlterList(ByVal u As List(Of String))
u(0) = u(0) & "somechange"
End Sub
End Class
The strange thing is pAlterList (even though it uses ByVal) DOES change the List(Of String).
After the call to the sub, the first item is "test0somechange". In my understanding, this should only happen if the List(Of String) would be passed as "ByRef".
What am I missing here?