I have my abstract base class A :
public abstract class A : ICloneable { public int Min { get; protected set; } public int Max { get; protected set; } public A(int low, int high) { this.Min = low; this.Max = high; }
which extends my class B :
public class B : A { public B(int low, int high) : base(low, high) { }
Since A is abstract, it cannot be created, but a derived class can. Is it possible to create a new instance of class B from class A ?
Suppose class A has many derived classes, how does it know which one needs to be created?
Well, I want to create an instance of the same class (or type) that A is currently.
That is, if I call the Clone method from class B , I want to instantiate a new B. If I call the Clone method from class C , I want to create a new C.
My approach was to write something like:
return new this(this.Min, this.Max);
But this does not work and does not compile.
Is it possible to accomplish this in C # ?
If it is not, is there an explanation so that I can understand?