Can someone please explain me the following:
quote from documentation
"Unlike other intrinsic data types, String is a reference type. When a
variable of reference type is passed as an argument to a function or
subroutine, a reference to the memory address where the data is stored is
passed instead of the actual value of the string. "
Code
Module Module1
Sub Main()
Dim s As String = "AAAA"
Mid(s, 2, 2) = "BB"
Trace.WriteLine(s)
Test(s)
Trace.WriteLine(s)
End Sub
Sub Test(ByVal st As String)
Trace.WriteLine(st)
Mid(st, 2, 2) = "CC"
Trace.WriteLine(st)
End Sub
End Module
Result of trace
ABBA
ABBA
ACCA
ABBA
If String is a reference type then the copy of a pointer is passed into the
sub
Mid supposed to replace a peace of memory occupied by this string
and it does it in Sub Main
Within the Sub Test the string part is replaced too
After Sub exits string is restored
Why is it restored?
Does it mean that there was actually a copy of a string created somewhere?
Supposed to be only a pointer copy, not a string copy.
--
Regards.
_____________________________________
Anatoli Trifonov
Software Developer & Consultant