Hi Frank,
Structure assignments are shallow copies, ie. only the ValueType fields
and strings. Strings - despite being a reference type - are a special case as
they are immutable, meaning that string data can only be pointed to by a
single variable/field/whatever at a time.
The documentation is correct. The 'value' of an object reference is the
address of the object not the object itself. So only the address gets copied.
So, any objects <referenced> by the structure (this includes arrays) will
not be copied (but the reference will). Nested structures, however, being
ValueTypes, <will> be copied (though not, of course, <their> referenced
objects)..
Here's an example:
Structure Nest
Public oMother As clsBird 'Reference copied
Public aoEggs() As structEgg 'Reference Copied
Public oCuckooEgg As structEgg 'Copied
Public dCreated As DateTime 'Copied
Public iHoursTaken As Integer 'Copied
Public sMaterials As String 'Copied
End Structure
I briefly mentioned 'shallow' versus 'deep' in the other posting so it'll
make more sense when you find that bit again. But here's some more about it.
All the above was about 'shallow' copying - valuetypes, references but not
actual objects. 'Deep' copying therefore goes beyond the object in question
(whether structure or class) and copies the linked objects too. 'Deep copying'
is a phrase associated with Clone and Copy methods. Each class that implements
these has a choice of whether to do it as a shallow copy or a deep copy. If
shallow is chosen, then MemberwiseClone can be returned. If it's a deep copy
though, the referenced objects must be asked to clone themselves as well. Each
of these, in turn, has the same choice and may respond with a shallow or deep
copy of itself.
In the following conversation Jay talks more about Cloning.
http://tinyurl.com/ta40
Regards,
Fergus