F
fperfect13
Hi,
I wanted to perform a deep copy of an array. Searching on google I ran
into different opinions :
C# Interview Questions
(http://blogs.wwwcoder.com/tsvmadhav/archive/2005/04/08/2882.aspx)
10.What's the difference between the System.Array.CopyTo() and
System.Array.Clone()?
The first one performs a deep copy of the array, the second one is
shallow. A shallow copy of an Array copies only the elements of the
Array, whether they are reference types or value types, but it does not
copy the objects that the references refer to. The references in the
new Array point to the same objects that the references in the original
Array point to. In contrast, a deep copy of an Array copies the
elements and everything directly or indirectly referenced by the
elements.
http://blogs.crsw.com/mark/articles/252.aspx
10.What's the difference between the System.Array.CopyTo() and
System.Array.Clone()?
The Clone() method returns a new array (a shallow copy) object
containing all the elements in the original array. The CopyTo() method
copies the elements into another existing array. Both perform a
shallow copy. A shallow copy means the contents (each array element)
contains references to the same object as the elements in the original
array. A deep copy (which neither of these methods performs) would
create a new instance of each element's object, resulting in a
different, yet identacle object.
(http://groups.msn.com/PuneUserGroup...Message=2957&LastModified=4675499377207834383)
27. What's the difference between the System.Array.CopyTo() and
System.Array.Clone()?
The first one performs a deep copy of the array, the second one is
shallow.
So I quote:
"The first one performs a deep copy of the array" ,
"Both perform a shallow copy."
I used System.Array.CopyTo() and it seems to perform only a shallow
copy, so how can I perform a deep one (one method would be to
serialize/deserialize the object) and the second quetion: Is CopyTo()
making a deep copy or not?
MSDN:"In contrast, a deep copy of an Array copies the elements and
everything directly or indirectly referenced by the elements."
I wanted to perform a deep copy of an array. Searching on google I ran
into different opinions :
C# Interview Questions
(http://blogs.wwwcoder.com/tsvmadhav/archive/2005/04/08/2882.aspx)
10.What's the difference between the System.Array.CopyTo() and
System.Array.Clone()?
The first one performs a deep copy of the array, the second one is
shallow. A shallow copy of an Array copies only the elements of the
Array, whether they are reference types or value types, but it does not
copy the objects that the references refer to. The references in the
new Array point to the same objects that the references in the original
Array point to. In contrast, a deep copy of an Array copies the
elements and everything directly or indirectly referenced by the
elements.
http://blogs.crsw.com/mark/articles/252.aspx
10.What's the difference between the System.Array.CopyTo() and
System.Array.Clone()?
The Clone() method returns a new array (a shallow copy) object
containing all the elements in the original array. The CopyTo() method
copies the elements into another existing array. Both perform a
shallow copy. A shallow copy means the contents (each array element)
contains references to the same object as the elements in the original
array. A deep copy (which neither of these methods performs) would
create a new instance of each element's object, resulting in a
different, yet identacle object.
(http://groups.msn.com/PuneUserGroup...Message=2957&LastModified=4675499377207834383)
27. What's the difference between the System.Array.CopyTo() and
System.Array.Clone()?
The first one performs a deep copy of the array, the second one is
shallow.
So I quote:
"The first one performs a deep copy of the array" ,
"Both perform a shallow copy."
I used System.Array.CopyTo() and it seems to perform only a shallow
copy, so how can I perform a deep one (one method would be to
serialize/deserialize the object) and the second quetion: Is CopyTo()
making a deep copy or not?
MSDN:"In contrast, a deep copy of an Array copies the elements and
everything directly or indirectly referenced by the elements."