views:

21

answers:

1

OK, I always get confused about this.

Let's say I have this code.

Public Sub Bar(byRef pMap as clsMap)
Dim foo as new FooClass()
pMap.listOfFoo.Add(foo)
end Sub

This would mean that referencing 'Foo' or the item stored in 'listOfFoo' would reference the same object, right? If I was to change a property of 'foo' - but not change it to a new object - both would still reference and would reflect the updated values?

+1  A: 

Yes, you're storing a reference pointer to the foo object, so if you modify a property in one place, it will be visible in all other places where foo is referenced.

If you want to make a copy of your object, you should consider object cloning.

Prutswonder