ICloneable.Clone 方法

定義

Creates a new object that is a copy of the current instance.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.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 的呼叫端無法相依于執行可預測複製作業的方法,所以我們建議您不要在公用 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.

如需複製、深度與淺層複本和範例的詳細資訊,請參閱 Object.MemberwiseCloneSee Object.MemberwiseClone for more information on cloning, deep versus shallow copies, and examples.

適用於

另請參閱