You apparently unaware of the very object-oriented fundamentals.
First to understand: there are two different types involved: compile-time and run-time type.
class MyBaseClass { internal byte somethingOld; }
class MyDerivedClass : MyBaseClass { internal int somethingNew; }
MyBaseClass b =
new MyDerivedClass();
bool isDerived = b is MyDerivedClass;
MyDerivedClass derived = b as MyDerivedClass;
isDerived = derived != null;
derived.somethingNew = 13;
You "pointer" terminology is incorrect for .NET, but let's forger about it for a while: you can thing of .NET references as of "pointers", to a certain point. The instance points to a block of memory. When you create an instance of
MyBaseClass
, you have only
somethingOld
in this block, not
somethingNew
. When you create derived class, the block of memory looks exactly the same, but
somethingNew
is appended to it. A variables point to united block of memory. From the standpoint of the variable
b
it points to smaller block, but at the same time it points to extended block of memory; common part is the same as that of
MyBaseClass
.
—SA