Re: arraylist copy



April 8, 2005

Thanks! Then what is the difference between CopyTo and Clone? MSDN
mentioned that clone creates a shallow copy and copyto creates a deep copy?
Thanks again!

Joseph MCAD


"Herfried K. Wagner [MVP]" <hirf-spam-me-here@xxxxxx> wrote in message
news:OlmslNGPFHA.580@xxxxxxxxxxxxxxxxxxxxxxx
> "Joseph MCAD" <anonymous@xxxxxxxxxxxxxxxxxxxxxxxxx> schrieb:
>> If you use the .Clone method then both arraylists will still point to the
>> same objects. HTH
>
> That is not true. 'Clone' will create a shallow copy of the arraylist:
>
> \\\
> Dim a1 As New ArrayList
> Dim a2 As ArrayList = a1.Clone()
> MsgBox(CStr(a1 Is a2))
> ///
>
> --
> M S Herfried K. Wagner
> M V P <URL:http://dotnet.mvps.org/>
> V B <URL:http://classicvb.org/petition/>


.



Relevant Pages

  • Re: Why deep cloning? Why shallow cloning? How is this related to references?
    ... Have you ever forgotten to create a copy constructor for a class ... a deep clone. ... And while a shallow clone works in .NET due to GC, ... You need to do a deep clone if you need to be able to update the ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Clone java collection & static variable??
    ... Your code is consistent with shallow copies. ... I thought a shallow copy would be when you call cloneon an array, ... It also clone object references inside the array. ... reference to the collection and clone the object reference it contains, ...
    (comp.lang.java.programmer)
  • Re: More On - deepcopy, Tkinter
    ... called to implement the shallow copy operation; ... So, if you have a class with attributes a, b, and c, and you want to ensure that deepcopy copies a and b, but doesn't copy c, I guess you could do ... As you can see, the deepcopy only creates deep copies of 2 of the 3 attributes, 'c' is simply copied across as a shallow copy. ...
    (comp.lang.python)
  • C# Generics, where keyword, and attributes.
    ... generic list collection that is cloneable (fully, not shallow) and ... So far the impl looks like this. ... public object Clone() ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: IClonable deep vs shallow, best practise
    ... object.MemberwiseClone for shallow copies? ... T Clone (bool deep); ... a deep clone or a shallow clone). ... interface, ...
    (microsoft.public.dotnet.languages.csharp)

Loading