class Parent
{
public int GetNo()
{
return 1;
}
}
class Child : Parent
{
public Child()
{
}
public int GetNo()
{
I have just come here so i could find a solution that doesn't use casts, but since i didn't find it here is one.
Maybe it can be of help for someone.
abstract class Parent
{
public int GetNo()
{
return GetNoImpl();
}
protected abstract int GetNoImpl();
}
class Child : Parent
{
public Child()
{
}
protected override int GetNoImpl();
{
return 2;
}
}
Parent p = new Child();
p.GetNo();
Note: the parent class is abstract.