Is it possible to invoke method A.F() from instance of B class except of using refactoring. Thanks..
class Program
{
public class A
{
public virtual void F()
{
Console.WriteLine( "A" );
}
}
public class B : A
{
public override void F()
{
Console.WriteLine( "B" );
}
}
static void Main( string[] args )
{
B b = new B();
//Here I need Invoke Method A.F() , but not overrode..
Console.ReadKey();
}
}
You may use the
newkeyword to have another definition of the same (named) method. Depending on the type of reference, you callA‘s ofB‘s implementation.If you feel that
newis not the right solution, you should consider to write two methods with a distinguished name.Generally, you can’t call the base implementation from outside the class if the method is properly overridden. This is an OO concept. You must have another method. There are four ways (I can think of) to specify this distinguished method:
newkeyword) It’s called hiding.new, but based on interface)