ICloneable Interface


支持克隆,即用与现有实例相同的值创建类的新实例。Supports cloning, which creates a new instance of a class with the same value as an existing instance.

public interface class ICloneable
public interface ICloneable
public interface ICloneable
type ICloneable = interface
Public Interface ICloneable


使用 ICloneable 接口,可以提供创建现有对象的副本的自定义实现。The ICloneable interface enables you to provide a customized implementation that creates a copy of an existing object. ICloneable 接口包含一个成员(Clone 方法),该方法旨在提供除 Object.MemberwiseClone提供的克隆支持。The ICloneable interface contains one member, the Clone method, which is intended to provide cloning support beyond that supplied by Object.MemberwiseClone. 有关克隆、深层副本和示例的详细信息,请参阅 Object.MemberwiseClone 方法。For more information about cloning, deep versus shallow copies, and examples, see the Object.MemberwiseClone method.

Notes to Implementers

ICloneable 接口只要求实现 Clone() 方法返回当前对象实例的副本。The ICloneable interface simply requires that your implementation of the Clone() method return a copy of the current object instance. 它不指定克隆操作是执行深层复制、浅表副本还是在两者之间执行操作。It does not specify whether the cloning operation performs a deep copy, a shallow copy, or something in between. 它也不需要将原始实例的所有属性值都复制到新实例。Nor does it require all property values of the original instance to be copied to the new instance. 例如,Clone() 方法执行除 IsReadOnly 属性之外的所有属性的浅表复制;它始终将此属性值设置为克隆的对象中的 falseFor example, the Clone() method performs a shallow copy of all properties except the IsReadOnly property; it always sets this property value to false in the cloned object. 由于 Clone() 的调用方不能依赖于执行可预测克隆操作的方法,因此,我们建议不要在公共 Api 中实现 ICloneableBecause callers of Clone() cannot depend on the method performing a predictable cloning operation, we recommend that ICloneable not be implemented in public APIs.



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

Applies to

See also