G
Guest
I have several Data Structures, say "mystruct" which contain arrays of bytes,
other structures, etc. I then dimension a variable (var1) as "mystruct" and
set the various elements var1 to data. I then dimension another variable
(var1save) as "mystruct" and set var1save = var1 with the intent of changing
var1 data elements and subsequently reasigning var1 back to it's original
values of var1save.
VB.Net makes only a shallow copy of var1 in var1save for anything other than
a simple varable type, i.e., only references for any arrays in the structure
are copied to var1save. Thus, everytime I change a var1 array variable,
var1save also reflects the new value thus negating the intent of saving var1
for future reinstatment.
Currently I have to copy each sub-element of var1 into var1save individually
in order to make a deep copy.
Is there any way to do a deep copy on objects other than breaking them down
into their simple elements and copying each one? This is very annoying to
have to write several lines of code to just copy one variable object to
another of the same type..
other structures, etc. I then dimension a variable (var1) as "mystruct" and
set the various elements var1 to data. I then dimension another variable
(var1save) as "mystruct" and set var1save = var1 with the intent of changing
var1 data elements and subsequently reasigning var1 back to it's original
values of var1save.
VB.Net makes only a shallow copy of var1 in var1save for anything other than
a simple varable type, i.e., only references for any arrays in the structure
are copied to var1save. Thus, everytime I change a var1 array variable,
var1save also reflects the new value thus negating the intent of saving var1
for future reinstatment.
Currently I have to copy each sub-element of var1 into var1save individually
in order to make a deep copy.
Is there any way to do a deep copy on objects other than breaking them down
into their simple elements and copying each one? This is very annoying to
have to write several lines of code to just copy one variable object to
another of the same type..