ICloneable 介面
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
支援複製 (Clone),使用與現有執行個體 (Instance) 相同的值建立新的執行個體。
public interface class ICloneable
C#
public interface ICloneable
C#
[System.Runtime.InteropServices.ComVisible(true)]
public interface ICloneable
type ICloneable = interface
[<System.Runtime.InteropServices.ComVisible(true)>]
type ICloneable = interface
Public Interface ICloneable
- 衍生
- 屬性
介面 ICloneable 可讓您提供自定義實作,以建立現有對象的複本。 ICloneable介面包含一個成員,Clone也就是方法,其旨在提供所提供Object.MemberwiseClone以外的複製支援。 如需複製、深層與淺層複製和範例的詳細資訊,請參閱 Object.MemberwiseClone 方法。
介面 ICloneable 只需要您的 方法實作 Clone() 傳回目前對象實例的複本。 它不會指定複製作業是否執行深層複製、淺層複製或介於兩者之間的某些專案。 也不需要將原始實例的所有屬性值複製到新的實例。 例如, Clone() 方法會執行屬性以外的 IsReadOnly 所有屬性的淺層複本;它一律會將這個屬性值設定為 false
複製的物件。 由於的 Clone() 呼叫端無法相依於執行可預測複製作業的方法,因此建議您 ICloneable 不要在公用 API 中實作。
Clone() |
建立目前執行個體複本的新物件。 |
產品 | 版本 |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |