Implement clone for a derived class.

In a derived class of a clonable class (implementing ICloneable) it is strongly advised
to implement the clone override. Obviously, this is only needed if new members have been
added.

for example:

class A : B
{
   int value1;
   public override object Clone()
   {
      A instance = (A)base.Clone();
      instance.value1 = value1;
      return (instance);
   }
}

The method Clone is being called from the context of A and creates an A object. Coming from a
C++ background this looks weird since you would expect a class of type B to be created. After
the initial Clone the extra member value1 has to be initialized as shown in the example.

Lastest update in September 2017, inital post in September 2017

Write a comment

I appreciate comments, suggestions, compliments etc. Unfortunately I have no time to reply to them. Useful input will be used for sure!