I would like to know if it is possible to access the underlying virtual method using the class of the inheriting class (which overrides the method).
I know this is not a good practice, but the reason I want to know this is technically possible. I do not follow this practice, just asking out of curiosity.
I saw several similar questions, but I did not receive the answer I am looking for.
Example:
public class Parent
{
public virtual void Print()
{
Console.WriteLine("Print in Parent");
}
}
public class Child : Parent
{
public override void Print()
{
Console.WriteLine("Print in Child");
}
}
class Program
{
static void Main(string[] args)
{
Child c = new Child();
child.Print();
((Parent)c).Print();
}
}
Please explain downvotes. Any reference to an existing similar question (with a satisfactory answer) to stackoverflow is an acceptable answer. Thank.
source
share