O'Reilly logo

.NET Programming: A Practical Guide Using C# by Pradeep Tapadiya

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Cloning

We know that when we assign one reference-type object to another, both the objects point to the same memory location after the operation is completed. If a member field in one object is changed, for example, it gets reflected in the other object.

Sometimes you might want to clone the object, i.e., create a duplicate copy of the object. The .NET Framework formalizes this notion of cloning by meaning of a standard interface, ICloneable. Here is its definition:

public interface ICloneable {
     Object Clone();
}

The interface defines just one method, Clone. The purpose of this method is to return a clone of the object. Any class that implements ICloneable must implement Clone and the necessary logic to duplicate the object.

Interface ICloneable ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required