Ok, I'll bite. Jabe, your code is not demonstrating how objects are passed per se, it's merely demonstrating out parameters. You can change the original class passed in in the latter procedure because you're passing byref, but either way you're creating a new instance so it doesn't prove much.
Take the code below, which is a cut down version of your. No matter whether the instance is passed byval or byref, it's a class so you're only passing a reference and the number will always be changed.
Take the code below, which is a cut down version of your. No matter whether the instance is passed byval or byref, it's a class so you're only passing a reference and the number will always be changed.
Visual Basic:
Public Class Tester
Public Shared Sub Main()
Dim t As New Tester, referenceType As New MyRefType
referenceType.RefTypeProp = 1
MessageBox.Show("Starting Value: " & referenceType.RefTypeProp.ToString())
t.PassByVal(referenceType)
MessageBox.Show("After being passed by value: " & referenceType.RefTypeProp.ToString())
t.PassByRef(referenceType)
MessageBox.Show("After being passed by reference: " & referenceType.RefTypeProp.ToString())
MessageBox.Show("It's always being changed because you're only passing a reference of the same object, NOT a copy of the object. Q.E.D.")
End Sub
Public Sub PassByVal(ByVal refType As MyRefType)
refType.RefTypeProp = 1000
End Sub
Public Sub PassByRef(ByRef reftype As MyRefType)
reftype.RefTypeProp = 9999
End Sub
End Class
Public Class MyRefType
Private m_intRefTypeProp As Integer
Public Property RefTypeProp() As Integer
Get
Return m_intRefTypeProp
End Get
Set(ByVal Value As Integer)
m_intRefTypeProp = Value
End Set
End Property
End Class