locked
Access base class protected method from derived class overridden method RRS feed

  • Question

  • Hi,

    I have a bit trouble with accessing base class protected method from derived class once I have overridden it.

      public class A
      {
        protected virtual void DoStuff()
        {
        }
      }
    
      public class B : A
      {
        private A a = new A();
    
        protected override void DoStuff()
        {
          base.DoStuff();
          a.DoStuff();  //complier goes nuts
        }
      }

    Have I misunderstood something? Is there another language construct to achieve the result?

     


    Robert
    Wednesday, June 9, 2010 6:23 AM

Answers

  • Make DoStuff method in class A as protected internal:

    public class A
    {
        protected internal virtual void DoStuff()
        {
        }
    }

    public class B : A
    {
        private A a = new A();

        protected internal override void DoStuff()
        {
            base.DoStuff();
            a.DoStuff();
        }
    }

    • Edited by Chris Vega Wednesday, June 9, 2010 6:42 AM code error
    • Marked as answer by iinlane Wednesday, June 9, 2010 6:59 AM
    Wednesday, June 9, 2010 6:41 AM