Deep copy ArrayList problem.

J

Jeff Louie

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
 
S

Steven Blair

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).
 
F

Frans Bouma [C# MVP]

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#)
------------------------------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top