What is Protected Internal Access Modifier in C#?If you want a member to be accessible only by the class containing it or its derived class which belongs to the same assembly in which the class is put up, then you have to use protected internal access modifier.
To demonstrate it, follow the steps shown below: Create
the following class: 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: 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
|