This is the scenario:
class BaseClass
{
public virtual string Prop {get; set;}
}
class ChildClass : BaseClass
{
public override string Prop {get; set;}
}
//program
...
ChildClass instance = new ChildClass;
Console.WriteLine(instance.Prop); //accessing ChildClass.Prop
...
The question is how to access BaseClass.Prop in a instance of ChildClass? Will casting do the trick?
Console.WriteLine((instance as BaseClass).Prop); //accessing BaseClass.Prop
-EDIT- A lot of people suggested casting. In C++ it would not work because polymorphism would still ensure that the child property is called. Isn't that the case in C#?
In C++ you would solve the issue by doing:
instance.(BaseClass::get_Prop())