Deep copy ArrayList problem.

  • Thread starter Thread starter Steven Blair
  • Start date Start date
Steven.. To be clear Clone on a string simply returns a new reference to
the same string.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnguine
t/html/drguinet5_update.asp

When is Clone not Clone?
But what if you want to have two separate strings, each containing the
same value? Well, generally you do not want this. Why waste the memory?
And because strings are immutable, there's not much point in having two
separate strings that have the same value.

So, although String implements IClonable, String.Clone simply returns a
reference to the same string without cloning it.

All is not lost, however: You can use the static method Copy if you
insist on having a second copy of the string.


Regards,
Jeff
 
Yup, I understand this. But my lasy query is to do with this line:

x.m_Names = this.m_Names.Clone() as ArrayList;

m_Names is an ArrayList and I am looking for confirmation that the last
class I posted would be a compleye deep copy?

I think I have everything covered now (one string and one ArrayList).
 
Steven said:
Frans,

Thanks for the reply.

Is this code a hit on performance?

depends on the graph. It takes performance of course, however it also
works no matter what graph you have. It can be an option if you have to
work with object instances of classes you don't control.

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
 
Back
Top