Hi All,

When I 'Add' an 'object' to a System.Collection (ArrayList, HashTable,...)
does it just put a 'reference' to the object in the Collection, or is it a
'deep copy' (a new instance of the object)?

SteveH

Re: Collections: Does 'Add' make a deep copy? by Mehdi

Mehdi
Wed May 10 15:54:06 CDT 2006

On Wed, 10 May 2006 16:47:51 -0400, Steve Hiemstra wrote:

> When I 'Add' an 'object' to a System.Collection (ArrayList, HashTable,...)
> does it just put a 'reference' to the object in the Collection, or is it a
> 'deep copy' (a new instance of the object)?

A reference (the object is not copied or cloned)

Re: Collections: Does 'Add' make a deep copy? by Ben

Ben
Fri May 12 13:18:36 CDT 2006

"Mehdi" <vioccc@REMOVEME.gmail.com> wrote in message
news:1mlvjr53elftt$.xeh7e26j6uf7$.dlg@40tude.net...
> On Wed, 10 May 2006 16:47:51 -0400, Steve Hiemstra wrote:
>
>> When I 'Add' an 'object' to a System.Collection (ArrayList,
>> HashTable,...)
>> does it just put a 'reference' to the object in the Collection, or is it
>> a
>> 'deep copy' (a new instance of the object)?
>
> A reference (the object is not copied or cloned)

Which gives you the choice of calling Add(o.Clone()) if you didn't want a
reference to a shared object.