protected internal .net access modifier

There are five access modifiers in .Net

  1. private
  2. public
  3. protected
  4. internal
  5. protected internal

While the first four are pretty straight forward, developers get confused with the protected internal. Many developers think members marked as protected internal may be accessed only by a descendant class that’s contained in the same assembly as its base class. However the key thing to note is protected internal is a union of protected and internal in terms of providing access but not restricting. This implies

  • Inherited types, even though they belong to a different assembly, have access to the protected internal members, and,
  • Types that reside in the same assembly, even if they are not derived from the type, also have access to the protected internal members.

protected internal means protected or internal, which is selected by including both a protected and an internal modifier in the member declaration.

Advertisements
Posted in .net. 3 Comments »

3 Responses to “protected internal .net access modifier”

  1. ajay singh chouhan Says:

    Thanks .

  2. Nitin Sharma Says:

    WOW..!!
    Good one… i was searching for this for a long time…
    no forum had this answer…its very easy to understand by the following lines:

    protected internal means protected or internal, which is selected by including both a protected and an internal modifier in the member declaration.

    Thanks,
    Nitin Sharma
    Software Programmer

  3. Sulaksha Says:

    Very good explanation of Protected Internal. The key to understand Protected Internal access modifier is to remember it as ‘Protected OR Internal’.
    Thanks for the article.

    Sulaksha


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: