D
Dmitry
Hi there,
Just came across this problem and was wondering if someone
can shed a light on it as it somewhat puzzles me.
Suppose I have the following classes:
Public Class CTest
Private m_objCMember As CMember
Public Function addMember(ByVal objMember As CMember)
m_objCMember = objMember
End Function
End Class
Public Class CMember
Public strFirstName As String
Public strLastName As String
End Class
And the following code that uses them:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim objTest As New CTest
Dim objMember As New CMember
objMember.strLastName = "last name"
objMember.strFirstName = "First name"
objTest.addMember(objMember)
objMember.strFirstName = "TEST FIST NAME"
End Sub
How come when I run the last line of code (objMember.strFirstName = "TEST
FIST NAME")
- the value in the property objTest.m_objCMember.strLastName changes to
"TEST FIST NAME" as well.
I thought in VB when you pass parameters by value, it just passes a copy of
the object or variable
but not the reference!
Am I missing something here?
Thanks a million in advance
Cheers,
Dmitry
Just came across this problem and was wondering if someone
can shed a light on it as it somewhat puzzles me.
Suppose I have the following classes:
Public Class CTest
Private m_objCMember As CMember
Public Function addMember(ByVal objMember As CMember)
m_objCMember = objMember
End Function
End Class
Public Class CMember
Public strFirstName As String
Public strLastName As String
End Class
And the following code that uses them:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim objTest As New CTest
Dim objMember As New CMember
objMember.strLastName = "last name"
objMember.strFirstName = "First name"
objTest.addMember(objMember)
objMember.strFirstName = "TEST FIST NAME"
End Sub
How come when I run the last line of code (objMember.strFirstName = "TEST
FIST NAME")
- the value in the property objTest.m_objCMember.strLastName changes to
"TEST FIST NAME" as well.
I thought in VB when you pass parameters by value, it just passes a copy of
the object or variable
but not the reference!
Am I missing something here?
Thanks a million in advance
Cheers,
Dmitry