As long as I know, we can't directly convert a base class to a derived (sub) class, because the base is not an instance of the derived and thus it'll result in null.
I have two classes, one derives from the other. I'm trying to figure out why I can convert baseClass1 to Sub without resulting in null while I can't convert the baseClass2 to Sub because it results in null.
Base baseClass1 = new Sub(); // The result is an instance of Base
Base baseClass2 = new Base(); // Same thing
Sub subClass1 = (Sub)baseClass1; // Doesn't result in null
Sub subClass2 = (Sub)baseClass2; // Does result in null
the baseClass1 is an instance of Base, even though I used the Sub() constructor. But using the Sub() constructor somehow allows me to convert the instance of Base to an instance of Sub without even losing the values that extra members of the Sub class hold (let's say I passed those values through the Sub() constructor in the first line).
What's the logic behind this? What is the true difference between baseClass1 and baseClass2, even though they're both instances of Base?