Strange behaviour on ByVal parameter ???

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
 
U

Uri Dor

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top