ICloneable 接口

定义

支持克隆,即用与现有实例相同的值创建类的新实例。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. 接口包含一个成员Clone , 即方法, 该方法旨在提供超出提供的克隆Object.MemberwiseClone支持。 ICloneableThe 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.

实施者说明

接口只要求实现Clone()方法返回当前对象实例的副本。 ICloneableThe 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()

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

适用于

另请参阅