Devildog74 wrote:
What would the difference be between your code and mine?
Wouldnt we both end up with 2 seperate objects that have the same values initially, but can be changed independently from one another?
No, your code simply creates two variables which reference the same object in memory. So if I do: customer1.CompanyName = "Foo" then customer2.CompanyName is also changed in "Foo" as it points to the same physical object in memory.
This is also the difference between a deep copy and a shallow copy: the first copies every bit of data into a physical different object, the second simply copies the referencing object but not the referenced object.
See an object variable, which customer1 and customer2 are, as pointers to a block of memory. When you do: customer1 = new CustomerEntity(), a new block of memory is allocated, filled in and the address is assigned to customer1 as the value.
So when you do customer1.CompanyName, you are in fact looking up the piece of memory reserved for CompanyName in the block of memory customer1 points to. When I do customer2=customer1, the address customer1 points to is now also the address customer2 points to.
This is different with value types, like ints, or structs. When you then do this
Dim i, j as Integer
i=10
j=i
you'll see that j gets the same VALUE as i, 10. This is because i is a value type, i.e. it doesn't point to a block of memory, it IS the block of memory, the value.