copyTo()和clone()之间的区别 [英] difference between copyTo ()and clone()
本文介绍了copyTo()和clone()之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对copyTo()和clone()有疑问.我阅读了一些理论理论,即复制用于深层复制,克隆用于浅层复制,但是r都复制了数据和结构.请有人对此提供帮助. "h2_lin">解决方案
Clone
方法返回一个包含原始数组中所有元素的新数组(浅表副本)对象.CopyTo
方法将元素复制到另一个现有数组中.两者都执行浅表复制.浅表副本表示内容(每个数组元素)包含对与原始数组中的元素相同的对象的引用.一个深层副本将为每个元素的对象创建一个新实例,从而产生一个不同但相同的对象.
请参考此 [ 解决方案
TheClone
method returns a new array (a shallow copy) object containing all the elements in the original array. TheCopyTo
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 identical objects.
Refer this[^]
--Amit.
这篇关于copyTo()和clone()之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文