You can use the keyword newto have a different definition for the same (named) method. Depending on the type of link, you call Aimplementations B.
public class A
{
public void F()
{
Console.WriteLine( "A" );
}
}
public class B : A
{
public new void F()
{
Console.WriteLine( "B" );
}
}
static void Main( string[] args )
{
B b = new B();
b.F();
A a = b;
a.F();
}
If you think this is newnot the right solution, you should consider writing two methods with a distinguished name.
, , . . . ( ) :
- .
- , (). .
- (
new). hiding. - . (
new, )