Strange behaviour on ByVal parameter ???

  • Thread starter Thread starter serge calderara
  • Start date Start date
S

serge calderara

Dear all,

I have really strange behviour when passing an object to a
function by value:

if I create a new object of myClass from the main
application as follow:

myObj = new (ObjSource)

then the instance is creted on a separate assambly an
reach the code of the constructor of myClass


public sub new (byval obj as object)

.....
....

' here I try to channge some object value
obj.name ="test"
end sub

At this time when the object is created and I return to
the calling point in my main application , the object is
also modifed in the main application, and it should be not
as it is pass by value to the constructo of myClass !!

What did I miss here?

thnaks for your information
regards
Serge
 
you're passing an object, so its "pointer" is passed by value. the
object itself isn't copied, so the changes you make to the object remain.

there's a reason "reference types" are so called - they're always passed
by reference.
 
Back
Top