Implement the ICloneable interface in a typesafe manner by just
calling the typed version of Clone.
| C# | Visual Basic | Visual C++ |
private Object ICloneable.Clone()
Private Function System.ICloneable.Clone As Object Implements ICloneable.Clone
private: virtual Object^ System.ICloneable.Clone () sealed = ICloneable::Clone
A deep copy of this object
Note that this method must be called with an explicit cast to ICloneable, and
that it is inherently virtual. For example:
CopyC#
Assume that ChildClass is inherited from ParentClass. Even though foo is declared with
ParentClass, it is actually an instance of ChildClass. Calling the ICloneable implementation
of Clone() on foo actually calls ChildClass.Clone() as if it were a virtual function.
ParentClass foo = new ChildClass();
ChildClass bar = (ChildClass) ((ICloneable)foo).Clone();