What is the difference between Array.Clone and Array.Copy Method

本文详细介绍了.NET中数组的浅拷贝与深拷贝的区别,以及数组复制的方法。浅拷贝仅复制数组元素,而不复制引用指向的对象;深拷贝则会递归地复制所有对象。文章还提供了多种数组复制的方式,包括使用不同长度类型指定范围的复制。

Array.Clone Method:

1).Creates a shallow copy of the Array.

--------------------------------------------------------------------------------------------------------------------------------

2). Remarks

A shallow copy of an Array copies only the elements of the Array, whether they are reference types or value types, but it does not copy the objects that the references refer to. The references in the new Array point to the same objects that the references in the original Array point to.

In contrast, a deep copy of an Array copies the elements and everything directly or indirectly referenced by the elements.

The clone is of the same Type as the original Array.

This method is an O(n) operation, where n is Length

---------------------------------------------------------------------------------------------------------------------------------Array.Copy Method  

1 ). Copies a range of elements in one Array to another Array and performs type casting and boxing as required.

2).  This member is overloaded. For complete information about this member, including syntax, usage, and examples, click a name in the overload list.

Overload List


  NameDescription
Public methodStatic memberCopy(Array, Array, Int32)Copies a range of elements from an Array starting at the first element and pastes them into another Array starting at the first element. The length is specified as a 32-bit integer.
Public methodStatic memberCopy(Array, Array, Int64)Copies a range of elements from an Array starting at the first element and pastes them into another Array starting at the first element. The length is specified as a 64-bit integer.
Public methodStatic memberCopy(Array, Int32, Array, Int32, Int32)Copies a range of elements from an Array starting at the specified source index and pastes them to another Array starting at the specified destination index. The length and the indexes are specified as 32-bit integers.
Public methodStatic memberCopy(Array, Int64, Array, Int64, Int64)Copies a range of elements from an Array starting at the specified source index and pastes them to another Array starting at the specified destination index. The length and the indexes are specified as 64-bit integers.

 

转载于:https://www.cnblogs.com/Jessy/archive/2010/10/25/1860603.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值