cjard
Well-known member
- Joined
- Apr 25, 2006
- Messages
- 7,081
- Programming Experience
- 10+
Suppose we have the following:
And we call it with:
When the method completes, we now have abc as the "All New SB By Ref" string builder.
I know why this is
But my question is, what, behind the scenes exactly is this doing:
It behaves exactly like ByVal but I cant think of a way of investigating whether it is just ignoring ByRef and passing ByVal, or whether it's doing some funky cloning.
Interestingly, I had also the same Sub, but with an Object arg:
When I pass in a child type:
only the second one gets a wiggly line and a: "Option Strict On disallows narrowing from type 'Object' to type 'System.Text.StringBuilder' in copying the value of 'ByRef' parameter 'o' back to the matching argument. " error
Is this a clue to what is going on?
VB.NET:
Public Sub MyByRefSub(ByRef sb As StringBuilder)
sb = New StringBuilder("All New SB By Ref")
End Sub
And we call it with:
VB.NET:
Dim abc as New StringBuilder("Old StringBuilder")
MyByRefSub(abc)
When the method completes, we now have abc as the "All New SB By Ref" string builder.
I know why this is
But my question is, what, behind the scenes exactly is this doing:
VB.NET:
MyByRefSub((abc))
It behaves exactly like ByVal but I cant think of a way of investigating whether it is just ignoring ByRef and passing ByVal, or whether it's doing some funky cloning.
Interestingly, I had also the same Sub, but with an Object arg:
VB.NET:
Public Sub MyByRefSub(ByRef o As Object)
o = New Object()
End Sub
When I pass in a child type:
VB.NET:
MyByRefSub((abc))
[U]MyByRefSub(abc)[/U]
only the second one gets a wiggly line and a: "Option Strict On disallows narrowing from type 'Object' to type 'System.Text.StringBuilder' in copying the value of 'ByRef' parameter 'o' back to the matching argument. " error
Is this a clue to what is going on?