1

Methods marked as virtual can be overridden in derived classes. One of the restrictions is that overriding and overridden methods must have same accessibility. Thus, if virtual method is marked as protected internal, then overriding method must also be marked as protected internal (it cannot be for example marked as just protected).

Since Page class overrides Control.CreateChildControls(), which is marked as protected internal, then Page.CreateChildControls() should also be marked as protected internal, but instead is marked as protected. How is that possible?

John Rasch
  • 62,489
  • 19
  • 106
  • 139
AspOnMyNet
  • 1,958
  • 4
  • 22
  • 39

2 Answers2

2

I probably did not get your question right. This is what i found at MSDN for Control.CreateChildControls

protected internal virtual void CreateChildControls()
Asad
  • 21,468
  • 17
  • 69
  • 94
  • Uh, I could swear I saw on MSDN Page class defining CreateChildControls() using just protected modifier. I keep messing things up today – AspOnMyNet Mar 03 '10 at 22:53
  • What you saw was right. It is Method signature and an example which are contradictory. I am confused with it as well. I probably will post a new question. with results I am getting – Asad Mar 03 '10 at 23:09
  • have posted a new poster with what more explanaition. http://stackoverflow.com/questions/2375792/overriding-protected-internal-with-protected-how-is-this-possible – Asad Mar 03 '10 at 23:24
1

Could it be you were looking at this incorrect example on MSDN:

protected override void CreateChildControls()
{               
   // Creates a new ControlCollection. 
   this.CreateControlCollection();

   // Create child controls.
    ChildControl firstControl = new ChildControl();
   firstControl.Message = "FirstChildControl";

   ChildControl secondControl = new ChildControl();
   secondControl.Message = "SecondChildControl";

   Controls.Add(firstControl);
   Controls.Add(secondControl);

   // Prevent child controls from being created again.
   ChildControlsCreated = true;
}

Source: http://msdn.microsoft.com/en-us/library/system.web.ui.control.createcontrolcollection.aspx

John Rasch
  • 62,489
  • 19
  • 106
  • 139