"Deep copy" / clone a collection

  • 12 years ago

    Hi All,

    I hope one of you can help me, as I'm getting nuts from all the Google searches.  I have an application for which I've defined a number of classes, grouped in collections.  E.g. a class Book with a number of properties and a collection/class Books that holds all the records for all the books entered into the system.  The question is: how can I copy the content of one collection into another collection without having to iterate through each individual record and property ?

    The "logical" Set oBooksNew = oBooksOld doesn't work, as it only creates pointers to the old collection, so any changes are automatically reflected in the new collection.  The closest I came to a solution is using the CopyMemory API, as that should really create a copy of the memory.  But when I use it in this form CopyMemory(oBooksNew, oBooksOld, LenB(oBooksOld), I get an error message that the LenB doesn't support this property/method.

    Who has the magic tip ?

    Thanks in advance,
    Erwin

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Debuggers don't remove bugs. They only show them in slow motion.”