What is difference between clone and copyTo method?

Posted by Kumarkrishna184 under C# on 3/23/2018 | Points: 10 | Views : 1330 | Status : [Member] | Replies : 3
What is difference between clone and copyTo method?

Thanks and Regards,
Krishna Kumar



Responses

Posted by: Vedikaledange on: 1/4/2019 [Member] Starter | Points: 25

Up
0
Down
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 would create a new instance of each element's object, resulting in a different, yet identacle object.

DOT NET

Kumarkrishna184, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Siddhipatel on: 1/28/2020 [Member] Starter | Points: 25

Up
0
Down
-->The Clone() method returns a new array object containing all the elements in the original array.

-->The CopyTo() method copies the elements into another existing array.



Software Developer at iFour Technolab Pvt Ltd

Kumarkrishna184, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ishan7 on: 11/18/2020 [Member] Starter | Points: 25

Up
0
Down
The clone is of the same type as the original Array.

The CopyTo() method copies the elements into another existing array. It copies the elements of one array to another pre-existing array starting from a given index (usually 0).

Both perform a shallow copy.

http://net-informations.com/faq/priq/clone.htm#:~:text=Clone()%20Vs%20CopyTo()%20Array&text=The%20clone%20is%20of%20the,Both%20perform%20a%20shallow%20copy%20.

Kumarkrishna184, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response