Issue with abstract classes
I am using a library of code which has some classes defined like such:
So we have a class A and a class B which inherits from A. Class A is also abstract.
public abstract class A
public class B : A
Now, we then have some function somewhere in the code which declares an instance of class B, does some operations on that object, and then returns it to the caller. It, however, returns it as if it were an instance of class A. It is something like this:
Now, as a client to this library, I would like to call this function which instantiates an object of class B and returns it to me, and I want to see it as being a B and not an A. So I do this:
public A ReturnInstanceOfA()
B myobj = new B();
Problem. I get this error: Cannot convert type 'A' to 'B' via a reference conversion, boxing conversion, unboxing conversion, wrapping conversion, or null type conversion
B myobj = ReturnInstanceOfA() as B;
How can I solve this issue?