In c#, how do I know what subclass an object is when stored as the parent?

Viewed 40

In c#, when a child class is stored as the parent, but still constructed as the child. Will typeOf return the child type or the parent type?

Given the situation above here is an example case.

Parent c = new Child();
if(typeOf(c) == Child)
    Console.Print("c is stored as a Child");
else if(typeOf(c) == Parent)
    Console.Print("c is stored as a Parent");

And if typeOf will not give me the child type, how do I get the child type?

0 Answers
Related