I know strings are immutable, so the minute you change a string reference's value .NET makes a brand new string on the heap.
But what if you don't change the value of a string reference; rather, you simply pass it into a function ByVal
-- does this operation copy the string value on the heap as well? My inclination is "no," but I'd like to confirm.
For example:
Public Function IsStringHello(ByVal test As String) As Boolean
Return (String.Compare(test, "Hello") = 0)
End Function
Calling program:
Dim myWord as String = "Blah"
Dim matchesHello as Boolean = IsStringHello(myWord)
I know passing myWord
by value makes a copy of the reference to "Blah", but since I have not tried to change the string itself, would it make another copy of the string on the heap?