views:

42

answers:

2

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?

+2  A: 

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

protected internal virtual void CreateChildControls()
Asad Butt
Uh, I could swear I saw on MSDN Page class defining CreateChildControls() using just protected modifier. I keep messing things up today
AspOnMyNet
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 Butt
have posted a new poster with what more explanaition. http://stackoverflow.com/questions/2375792/overriding-protected-internal-with-protected-how-is-this-possible
Asad Butt
+1  A: 

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
Yes, for a moment I thought I was dreaming. Thanx mate
AspOnMyNet