TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
private protected access modifier in C# restricts member visibility to the declaring class, types nested within the declaring class, and derived classes that reside within the same assembly (or a designated friend assembly). It functions as a logical AND operation between the internal (assembly-level) and protected (inheritance-level) modifiers. To access a private protected method from outside the declaring class or its nested types, the calling type must inherit from the containing class and be compiled into the same assembly, unless the defining assembly explicitly grants access via the [InternalsVisibleTo] attribute.
This modifier was introduced in C# 7.2 to provide stricter encapsulation boundaries compared to protected internal, which acts as a logical OR (accessible to any type in the same assembly, or any derived type in any assembly).
Access Rules Matrix
| Caller Location | Relationship to Base Class | Access Granted? |
|---|---|---|
| Same Assembly | Declaring class or nested type | Yes |
| Same Assembly | Derived class | Yes |
| Same Assembly | Unrelated (Not derived, not nested) | No (Compiler Error) |
| Different Assembly | Derived class | No* (Yes if [InternalsVisibleTo] is applied) |
| Different Assembly | Unrelated | No (Compiler Error) |
Syntax and Compilation Behavior
The following code block demonstrates the mechanical enforcement of theprivate protected modifier across assembly boundaries, nested types, and inheritance hierarchies.
Technical Constraints
- Language Version: Requires C# 7.2 or later.
- Valid Targets: Can be applied to methods, properties, fields, events, and nested types within a
classorrecord. - Invalid Targets: Cannot be applied to members of a
struct(as structs do not support inheritance) or members of aninterface(prior to C# 8.0 default interface methods). It also cannot be applied to top-level types (classes or structs declared directly within a namespace).
Master C# with Deep Grasping Methodology!Learn More





