C#: Any way to skip over one of the base calls in polymorphism?

后端 未结 7 1279
一个人的身影
一个人的身影 2021-01-17 16:34
class GrandParent
{
    public virtual void Foo() { ... }
}

class Parent : GrandParent
{
    public override void Foo()
    {
       base.Foo();

       //Do additi         


        
7条回答
  •  北恋
    北恋 (楼主)
    2021-01-17 16:43

    No, this isn't possible. Imagine how crazy things would be if this was possible.

    If you want something specific skipped in the Child case, consider reworking your design to better represent what you need (e.g. maybe you need to override something else in the Child class, too). Or, you could provide another Foo() in the Parent class that doesn't do anything except call its base.Foo().

提交回复
热议问题