Question: I have a class B which derives from another class A. Class A implements a Copy method. How can I implement a Copy method in class B which makes use of A.Copy() ?

There are reasons (possibly not good ones) why I have not used Clone and why I would like to have this inheritance structure.

```
class A 
{
    ... properties ...
    public A Copy()
    {
        ...copy properties....
    }
}

class B : A 
{
    ... one extra property ...
    public B Copy()
    {
        // how to copy base()??
        ...copy extra propertie....
    }
}

```

Answer: 
A common solution is to define a constructor that copies all properties from another instance. Derived classes then copy the properties defined in their class and call the base constructor to copy the properties of the base class.

```
class A 
{
    // properties

    protected A(A other)
    {
        // copy properties
    }

    public A Clone()
    {
        A clone = CloneCore() as A;
        if (clone == null)
            throw new NotImplementedException("Clone Not Implemented Correctly");
        return clone;
    }

    protected virtual object CloneCore()
    {
        return new A(this);
    }
}

```

```
class B : A 
{
    // one extra property

    protected B(B other) : base(other)
    {
        // copy extra property
    }

    public new B Clone()
    {
        B clone = CloneCore() as B;
        if (clone == null)
            throw new NotImplementedException("Clone Not Implemented Correctly");
        return clone;
    }

    protected override object CloneCore()
    {
        return new B(this);
    }
}

```
Short answer: You can't. 

Since `A.Copy()` returns type `A` it cannot be changed to return a `B`.

There is already a method on your object that will copy all of the fields into a new object. It's called `object.MemberwiseClone()`. Be careful with this though, because it will perform a **shallow copy**. (Meaning all reference type members will point to the existing objects).

From what I've found, you typically want a **deep copy**, unfortunately this means that you will have to write a 'deep copy' method in *every class* that can be contained by `A`. 

A `Clone()` method is typically understood to be a deep copy. (comments always help) And, it returns `object`. This will require a cast if you want a `B` back. There's not really a good way around this since you cannot change the signature for an inherited method.

One more thing: don't use the `new` keyword when defining a function. It breaks polymorphism and can result in hard-to-find bugs.

```
public class A : IClonable {
   public ReferenceType member1;
   public int member2;

   public object Clone() {
       var clone = this.MemberwiseClone() as A;  //shallow copy
       clone.CloneReferenceMembers();            //deep copy
       return clone;
   }
   public virtual void CloneReferenceMembers(){
      this.member1 = this.member1.Clone();
   }

}

public class B : A {
   public AnotherReferenceType member3;
   public int member4;

    public override void CloneReferenceMembers(){
       base.CloneReferenceMembers();
       this.member3 = this.member3.Clone();
   }
}

```