Clarification on 'Internal' access modifier in c#
Posted on 2010-09-23
I have been revising for an upcoming test on .net/c# and would like to clarify something. I like to fully understand things before I 'tick' them off in my head.
So, within .net, we have the following access modifiers;
Public (no problem here)
Private (no problem here)
Protected (no problem)
However, I am a little confused with the 'internal' and then subsequent 'protected internal'
The MSDN explanation of 'internal' is "Access is limited to the current assembly."
Now,my understanding of an assembly is a collection of modules and resources compiled into an 'assembly' be that .exe or .dll
So based on this assumption, how can an internal modifier be limited to an assembly, based on this;
I have an 'assembly' in which i have various files, which contain my custom classes. If I declared an 'internal' value (int) in one of these classes, it will compile. If I then instantiated this class from another assembly (my ui), I can access it.
Now I do see that when you create an 'internal' class, then it is inaccessible from another assembly. So, what about the internal value (int). Am I basically breaking an unwritten rule by declaring my value (int) as internal or am I missing something completely.
Although not tested, I would assume the same is going to come up with protected internal to some degree.
Can anyone clarify this for me.