The C# Language Reference on MSDN defines 'protected internal' as "Access is limited to the current assembly or types derived from the containing class". But from a semantic point of view, 'protected internal' sounds to me like 'both protected and internal' which means the member will be accessible only to those derived classes with in the same assembly. Is there any access modifier that has a meaning to the same effect?
Asked
Active
Viewed 6,467 times
13
-
this always bugged me too.. Similar question: http://stackoverflow.com/questions/7000871/internal-protected-property-still-accessible-from-a-different-assembly – nawfal May 19 '13 at 03:48
2 Answers
18
C# does not have any such access modifier.
However, the CLR does support it, as the FamANDAssem access level (protected internal
is FamORAssem)

SLaks
- 868,454
- 176
- 1,908
- 1,964
-
5protected internal is supported in C#. It's protected private that's only available in C++. protected internal is FamORAssem. protected private is FamANDAssem. – BlackWasp Sep 30 '12 at 13:52
-
BlackWasp is correct. C# does support protected internal. See http://msdn.microsoft.com/en-us/library/ms173121(v=vs.110).aspx. – akton Sep 30 '12 at 13:55
-
4
-
1
-
3Good point, I've re-read and I'm an idiot (not for the first time and I'm sure not for that last time either) :) – BlackWasp Sep 30 '12 at 14:48
1
No, there is no such modifier. Internal
should suffice, as you should be able to know from within other types in the same assembly what is legal to call and what is not.

Adam Robinson
- 182,639
- 35
- 285
- 343
-
Thanks! but what I am trying to get to was that it is not possible to define a member in such a way that it will be accessible only to derived classes AND within the same assembly. Even though I cannot right now think of a scenario where having such an access modifier would come in handy, it is good to know that there is no such modifier that would allow the programmer to say, this member is 'both protected and internal' – Asegid Debebe Oct 01 '12 at 04:32
-
2@adfs: Being able to declare a method as `internal` *and* `protected` would be better than `internal` only in the scenario where the method should take a parameter of a `protected` nested class type, especially if that protected class had members of internal types. – supercat May 07 '13 at 17:48