ICloneable.Clone 方法


建立目前執行個體複本的新物件。Creates a new object that is a copy of the current instance.

 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.