I have read that String was a "reference type", unlike integers. MS website
I tried to test its behavior.
Dim s As New TheTest
s.TheString = "42"
Dim z As String = s.GimmeTheString
z = z & "000"
Dim E As String = s.TheString
Public TheString As String
Public Function GimmeTheString() As String
Public Sub GimmeByref(s As String)
s = TheString
The confusion comes about because regardless of type, argument passing in VB is pass by value by default.
If you want to pass an argument by reference, you need to specify the argument type as
Public Sub GimmeByref(ByRef s As String)
You also need to understand the difference between mutating a value and re-assigning a variable. Doing
s = TheString inside the method doesn’t mutate the value of the string, it reassigns
s. This can obviously be done regardless of whether a type is a value or reference type.
The difference between value and reference types comes to bear when modifying the value itself, not a variable:
Strings in .NET are immutable and thus don’t possess any such methods (same as integers). However,
List(Of String), for instance, is a mutable reference type. So if you modify an argument of type
List(Of String), even if it is passed by value, then the object itself is modified beyond the scope of the method.