Passing Objects ByVal in VB

Passing Objects ByVal in VB

You can pass Object parameters to a sub ByVal just as you pass other parameters. But what is the difference between passing Objects ByVal and ByRef, since an object variable always contains a reference to the object in memory and not the object itself?
An object parameter passed ByVal behaves in a similar fashion as any other parameter passed ByVal. The changes made to them inside the called sub procedure are not visible in the calling program. But the fact that the object variable only contains the reference to the actual object makes it more complex. For example:

 ''''''''''''''''''''''''''''''''''Public Sub ub TestProc(ByVal ObjVal As cTest, ByRef objRef As cTest)  dim objNew as new cTest  objVal.Prop =


Share the Post: