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. difference between

difference between

Scheduled Pinned Locked Moved C#
data-structuresquestion
6 Posts 5 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.
  • R Offline
    R Offline
    Ravi Shankar43
    wrote on last edited by
    #1

    What’s the difference between the System.Array.CopyTo() and System.Array.Clone()?

    R B I J 4 Replies Last reply
    0
    • R Ravi Shankar43

      What’s the difference between the System.Array.CopyTo() and System.Array.Clone()?

      R Offline
      R Offline
      rah_sin
      wrote on last edited by
      #2

      i think System.Array.CopyTo() is used to add array elements to another existing array object from the index which we specify onwards where as System.Array.Clone() is used to create similar array object with same elements

      rahul

      1 Reply Last reply
      0
      • R Ravi Shankar43

        What’s the difference between the System.Array.CopyTo() and System.Array.Clone()?

        B Offline
        B Offline
        Bhupi Bhai
        wrote on last edited by
        #3

        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. Regards, Bhupi Bhai.

        1 Reply Last reply
        0
        • R Ravi Shankar43

          What’s the difference between the System.Array.CopyTo() and System.Array.Clone()?

          I Offline
          I Offline
          IamMohan
          wrote on last edited by
          #4

          The first one (System.Array.CopyTo()) performs a deep copy of the array, the second one(System.Array.Clone()) is shallow copy of the array:) Mohan

          B 1 Reply Last reply
          0
          • I IamMohan

            The first one (System.Array.CopyTo()) performs a deep copy of the array, the second one(System.Array.Clone()) is shallow copy of the array:) Mohan

            B Offline
            B Offline
            Bhupi Bhai
            wrote on last edited by
            #5

            Mohan, Neither of the two perform deep copy. Both CopyTo and Clone perform Shallow copy. Regards, Bhupi Bhai.

            1 Reply Last reply
            0
            • R Ravi Shankar43

              What’s the difference between the System.Array.CopyTo() and System.Array.Clone()?

              J Offline
              J Offline
              jdkulkarni
              wrote on last edited by
              #6

              Visit http://www.thescripts.com/forum/thread269691.html[^] One para from the same. A copyto makes a copy of the values in/from a one dimensional array (where the type of the sender and the receiver has to be the same and the receiver completly exist already). A clone copies the references, therefore using the references in the clone will have the same effect on the referenced objects as using the original array. Although you can have at a certain moment in a clone more references than in the original or/and visa versa. A deepcopy you have to make yourself. The system does not know what objects you have added to by instance your arraylist. (It can be by instance a thousand times deep arraylist).

              Jayant D. Kulkarni Brainbench Certified Software Engineer in C#, ASP.NET, .NET Framework and ADO.NET

              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