Hello everyone!
Reading http://stackoverflow.com/questions/408101/which-is-faster-byval-or-byref made me wonder whether the comments in there did apply to Strings
in terms of performance. Since strings are copied before being passed, isn't it much more efficient (if the callee doesn't need a copy of string course) to pass strings ByRef
?
Thanks,
CFP.
Edit: Consider this code, which made me think there was some kind of copy going on:
Sub Main()
Dim ByValStr As String = "Hello World (ByVal)!"
Dim ByRefStr As String = "Hello World (ByRef)!"
fooval(ByValStr)
fooref(ByRefStr)
Console.WriteLine("ByVal: " & ByValStr)
Console.WriteLine("ByRef: " & ByRefStr)
Console.ReadLine()
End Sub
Sub fooval(ByVal Str As String)
Str = "foobar"
End Sub
Sub fooref(ByRef Str As String)
Str = "foobar"
End Sub
It outputs:
ByVal: Hello World (ByVal)!
ByRef: foobar