Using the C# language constructs, you cannot explicitly call the base function from outside the scope of A
or B
. If you really need to do that, then there is a flaw in your design - i.e. that function shouldn't be virtual to begin with, or part of the base function should be extracted to a separate non-virtual function.
You can from inside B.X however call A.X
class B : A
{
override void X() {
base.X();
Console.WriteLine("y");
}
}
But that's something else.
As Sasha Truf points out in this answer, you can do it through IL.
You can probably also accomplish it through reflection, as mhand points out in the comments.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…