Dimitris999
New Member
In BeginnersGuide, on page 161 says:
'All other types including arrays of primitives types and strings are categorized as non-primitive types.
When you pass a non-primitive to a sub or when you assign it to a different variable, a copy of the reference is passed'.
I try to see what happen to strings with the following code:
Stra prints "a" and Strb prints "b". The value of Stra not changed after changing Strb. They Remain two separate variables.
I try the above code using Stringbuilder instead of String
I see that both two variables are print "ab".
So, the String variable types are primitive and when assign to a different variable or a sub copy their contents (pass by value) while Stringbuilder is non-primitive and copy the reference and not the content (pass by reference) ?
Is this true?
'All other types including arrays of primitives types and strings are categorized as non-primitive types.
When you pass a non-primitive to a sub or when you assign it to a different variable, a copy of the reference is passed'.
I try to see what happen to strings with the following code:
B4X:
Dim Stra As String
Dim Strb As String
Stra = "a"
Strb = Stra
Strb = "b"
Log (Stra)
Log (Strb)
Stra prints "a" and Strb prints "b". The value of Stra not changed after changing Strb. They Remain two separate variables.
I try the above code using Stringbuilder instead of String
B4X:
Dim Stra As StringBuilder
Dim Strb As StringBuilder
Stra.Initialize
Strb.Initialize
Stra.Append("a")
Strb = Stra
Strb.Append("b")
Log (Stra)
Log (Strb)
I see that both two variables are print "ab".
So, the String variable types are primitive and when assign to a different variable or a sub copy their contents (pass by value) while Stringbuilder is non-primitive and copy the reference and not the content (pass by reference) ?
Is this true?