Assume this base class:
public class BaseClass {
public BaseClass Clone() {
/* Returns a full copy of the object. */
}
/* Constructors here */
}
And this derived class:
public class ExtendedBaseClass : BaseClass {
/* ... */
/* Constructors here */
}
If I understand correctly, if an instance of ExtendBaseClass
, calls Clone
, an object of type BaseClass
will be returned. So, this will fail because an explicit cast is missing:
BaseClass bc = new();
ExtendedBaseClass ebc = bc.Clone();
I have two questions:
- Is my understanding correct?
- Is there a way to prevent an explicit cast from being needed when
Clone()
is called?