
What
is Protected Internal Access Modifier
|
Create
the following class:
public class sampleClass {
protected internal int member1;
}
Name the class as sampleAssembly.cs and Compile this class by specifying /target:library
Create
a new program called testClass.cs with the following code:
public class testClass:sampleClass {
public static void Main() {
member1 = 10;
}
}
Compile this program by specifying /reference:sampleAssembly.dll
Now try to execute testClass. You will end up in the following error:
sampleClass.member1 not visible outside assembly
This is because, you try to access protected internal member of sampleClass from its derived class which is referencing the assembly but not belonging to that assembly. If the testClass is also part of sampleAssembly then you can very well access member1 without any errors.
Note that protected internal access modifier should not be used as a modifier on a class. If you try to use it, then you will end up in the following error: Namespace elements cannot be explicitly declared as private, protected, or protected internal
_______________________________________________________________________
FREE Subscription
Subscribe
to our mailing list and receive new articles
through email. Keep yourself updated with latest
developments in the industry.
Note
: We never rent, trade, or sell my email lists to
anyone.
We assure that your privacy is respected
and protected.
Visit .NET Programming Tutorial Homepage
______________________________________________________