Diff between internal & protected internal modifiers..  
Author Message
MSP.Saami





PostPosted: Visual C# Language, Diff between internal & protected internal modifiers.. Top

hi,

We know that if we declare anything as internal, that will be accessible within the assembly. And any protected members will be accessed by the subclasses within the assembly. But what is the use of declaring a member as protected internal Any one pls, help me in this regard...

thanx...




Visual C#19  
 
 
Geert Verhoeven





PostPosted: Visual C# Language, Diff between internal & protected internal modifiers.. Top

Hi,

It is indeed a bit confusing but if you read below you will see the difference:

protected
Access is limited to the containing class or types derived from the containing class.

internal
Access is limited to the current assembly.

protected internal
Access is limited to the current assembly or types derived from the containing class.

The important part is the last OR.
Do you understand the difference


Greetz,

Geert

Geert Verhoeven
Ausy Belgium

My Personal Blog



 
 
Axe22





PostPosted: Visual C# Language, Diff between internal & protected internal modifiers.. Top

A class in a different assembly derived from the class with the pi attribute still has access to it. If it was internal only the derived class in the other assembly couldn't reach it. And, of course, protected only means the derived class in any assembly can reach it.


 
 
Gabriel Lozano-Moran





PostPosted: Visual C# Language, Diff between internal & protected internal modifiers.. Top

To add to Geert's comment:

internal is the same as public private (CLI), which means public access to the containing assembly but private to all other assemblies.

protected internal is public protected private, which means public to the containing assembly, protected to all derived types (in any assembly) but private to types outside the containing assembly.



 
 
Figo Fei - MSFT





PostPosted: Visual C# Language, Diff between internal & protected internal modifiers.. Top

hi,

What Geert Verhoeven explained is pretty good, and additionally I give some info about these accessibility modifiers to make it perfect :

CLR Term C# Term VB Term Description
Private private Private Accessible in the defining type
Family protected Protected Accessible in this or its derived types without regard to assembly
Assembly internal Friend Accessible in the defining assembly
Family and Assembly (not support) (not support) Accessible by methods in this type and by derived types in the defining assembly
Family or Assembly protected internal Protected Friend Accessible in this or its derived types, or in any type defined in the defining assembly
Public public Public Accessible to all

Thank you



 
 
MSP.Saami





PostPosted: Visual C# Language, Diff between internal & protected internal modifiers.. Top

hi all,

thanx all..I got it..thanx once again...