ICloneable.Clone 方法

定义

创建作为当前实例副本的新对象。Creates a new object that is a copy of the current instance.

public:
 System::Object ^ Clone();
public object Clone ();
abstract member Clone : unit -> obj
Public Function Clone () As Object

返回

作为此实例副本的新对象。A new object that is a copy of this instance.

注解

生成的克隆必须与原始实例具有相同的类型, 或与其兼容。The resulting clone must be of the same type as, or compatible with, the original instance.

Clone实现可以执行深层复制或浅表复制。An implementation of Clone can perform either a deep copy or a shallow copy. 在深层复制中, 所有对象都是重复的;在浅表复制中, 只复制顶级对象, 而较低级别包含引用。In a deep copy, all objects are duplicated; in a shallow copy, only the top-level objects are duplicated and the lower levels contain references. 因为的Clone调用方不能依赖于执行可预测的克隆操作的方法, ICloneable所以我们建议不要在公共 api 中实现。Because callers of Clone cannot depend on the method performing a predictable cloning operation, we recommend that ICloneable not be implemented in public APIs.

有关Object.MemberwiseClone克隆的详细信息, 请参阅深度与浅表副本和示例。See Object.MemberwiseClone for more information on cloning, deep versus shallow copies, and examples.

适用于

另请参阅