Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Deep copy and shallow copy with List<> [modified]

Deep copy and shallow copy with List<> [modified]

Scheduled Pinned Locked Moved C#
questioncsharpdata-structures
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jeffb42
    wrote on last edited by
    #1

    Hello, I'm using C# 2.0 generics in an application I'm writing and I have a question about copying one list to another. The List<> generic doesn't seem to have a deep copy method. It has CopyTo() but this copies to an array, not to a List<>. Suppose I have a large list of objects: main() { List original = new List(); // add 10000 MyClass objects to original... // ...... List backup = new List(); ShallowCopy(original, backup); } static void ShallowCopy(List source, List dest) { dest.Clear(); foreach(T t in source) { dest.Add(t); } } OK, this gives me a shallow copy, but what if I want a deep copy? It doesn't look like there's a deep copy built into generics... or what am I missing? Thanks, Jeff -- modified at 17:27 Wednesday 7th February, 2007

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups