Ok we know that when passing "byVal" in methods strings, booleans
e.t.c their values do not change, but when passing "ByRef" they do
change. However when passing objects it does not matter if we pass it
"ByVal" or "ByRef". Either way the object changes!! Lets see that in
practice:
Create a Web project and place a button on the form. Then create a class and the following methods:
Public Class Class1
Private _mytitle As String
Public _mytitlee As String
Public Property mytitle() As String
Get
Return _mytitle
End Get
Set(ByVal Value As String)
_mytitle = Value
End Set
End Property
Public Sub setTitle(ByVal myob As Class1)
myob.mytitle = "new title"
End Sub
Public Sub setTitlee(ByVal str As String)
str = "this the new title"
End Sub
End ClassYou see we pass "ByVal" a string and a class. Now let's go to the form. Write the following for the click event of the button:
'the object that we are going to pass
Dim myobj As New Class1
'.....
Dim myclasss As New Class1
Dim str As String = ""
myclasss.setTitle(myobj)
myclasss.setTitlee(str)
Response.Write(myobj.mytitle)
Response.Write(str)Now run the project ... you will see the unexpected. The object does change value allthough it's beeing passed by value...