Hi
What I have learned is that a variable is just a reference when dealing with Objects.
Are you supposed to use ByVal or ByRef in functions? They produce the same result or have I missed something?
Regards
/Niklas
Public Class Main
Shared Sub Main()
Dim testPropObj As New MyPropertObject
testPropObj.MyI nt = 1
Console.WriteLi ne("Org: testPropObj.MyI nt = " & testPropObj.MyI nt)
ChangeObjectByV al(testPropObj)
Console.WriteLi ne("ByVal: testPropObj = " & testPropObj.MyI nt)
ChangeObjectByR ef(testPropObj)
Console.WriteLi ne("ByRef: testPropObj = " & testPropObj.MyI nt)
Console.WriteLi ne("Press Enter to exit...")
Console.ReadLin e()
End Sub
Public Shared Sub ChangeObjectByV al(ByVal myObject As MyPropertObject )
myObject.MyInt = 5
End Sub
Public Shared Sub ChangeObjectByR ef(ByRef myObject As MyPropertObject )
myObject.MyInt = 6
End Sub
End Class
Public Class MyPropertObject
Public MyInt As Integer
End Class
What I have learned is that a variable is just a reference when dealing with Objects.
Are you supposed to use ByVal or ByRef in functions? They produce the same result or have I missed something?
Regards
/Niklas
Public Class Main
Shared Sub Main()
Dim testPropObj As New MyPropertObject
testPropObj.MyI nt = 1
Console.WriteLi ne("Org: testPropObj.MyI nt = " & testPropObj.MyI nt)
ChangeObjectByV al(testPropObj)
Console.WriteLi ne("ByVal: testPropObj = " & testPropObj.MyI nt)
ChangeObjectByR ef(testPropObj)
Console.WriteLi ne("ByRef: testPropObj = " & testPropObj.MyI nt)
Console.WriteLi ne("Press Enter to exit...")
Console.ReadLin e()
End Sub
Public Shared Sub ChangeObjectByV al(ByVal myObject As MyPropertObject )
myObject.MyInt = 5
End Sub
Public Shared Sub ChangeObjectByR ef(ByRef myObject As MyPropertObject )
myObject.MyInt = 6
End Sub
End Class
Public Class MyPropertObject
Public MyInt As Integer
End Class
Comment