OOPs whats happening here in this assignment

c#, oop

Solution

No, it's broadly equivalent to:

DerivedFromClassA derivedObject = null;
if (classAObject is DerivedFromClassA)
{
    derivedObject = (DerivedFromClassA) classAObject;
}

In other words, the result will either be a null reference, or a reference to the same object, but statically typed to be of the derived type.

Problem

I came across these lines of code ``` ClassA classAObject; //some lines of code that hydrate 'classAObject' DerivedFromClassA derivedObject = classAObject as DerivedFromClassA; ``` whats going on, on the last line? Is it assigning to derivedObject only those values that are in common between derivedObject and classAObject ?

Original source