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 of List without serialize/deserialize

Deep copy of List without serialize/deserialize

Scheduled Pinned Locked Moved C#
designsysadminhelpquestion
4 Posts 3 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.
  • C Offline
    C Offline
    c0ax_lx
    wrote on last edited by
    #1

    Is there any easier/other way to deep copy a List other than serialize to memorystream and then deserialize into a new object? The List comes from a method on a remoting server in singleton mode and fills a combobox on a UI. So i guess filling it directly with the ref would be bad practice.

    If it' stuck, DO NOT pull harder!

    E 1 Reply Last reply
    0
    • C c0ax_lx

      Is there any easier/other way to deep copy a List other than serialize to memorystream and then deserialize into a new object? The List comes from a method on a remoting server in singleton mode and fills a combobox on a UI. So i guess filling it directly with the ref would be bad practice.

      If it' stuck, DO NOT pull harder!

      E Offline
      E Offline
      Ed Poore
      wrote on last edited by
      #2

      Take a look at the Clone method.


      My Blog[^]

      C 1 Reply Last reply
      0
      • E Ed Poore

        Take a look at the Clone method.


        My Blog[^]

        C Offline
        C Offline
        c0ax_lx
        wrote on last edited by
        #3

        List does not interace iCloneable so i would have to Foreach(someclass myobject in mylist){ newlist.add(myobject.clone()); } And the class of the list needs to interface ICloneable am i right?

        If it' stuck, DO NOT pull harder!

        T 1 Reply Last reply
        0
        • C c0ax_lx

          List does not interace iCloneable so i would have to Foreach(someclass myobject in mylist){ newlist.add(myobject.clone()); } And the class of the list needs to interface ICloneable am i right?

          If it' stuck, DO NOT pull harder!

          T Offline
          T Offline
          TJoe
          wrote on last edited by
          #4

          Yes, you will need to create a copy of the list yourself. While, List<T> does not implement ICloneable, ArrayList does. But even so, it's only a swallow copy.

          Take care, Tom ----------------------------------------------- Check out my blog at http://tjoe.wordpress.com

          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