ICloneable ICloneable ICloneable ICloneable Interface

定义

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

public interface class ICloneable
[System.Runtime.InteropServices.ComVisible(true)]
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.MemberwiseCloneThe 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.

实施者说明

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属性; 它始终将此属性的值设置为false中克隆的对象。For 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()不能依赖于执行的可预测性的方法克隆操作,我们建议,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.

方法

Clone() Clone() Clone() Clone()

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

适用于

另请参阅