ADocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
protected method in C# is a class member encapsulated with the protected access modifier, restricting its visibility strictly to the declaring class and any types derived from that class, regardless of assembly boundaries. It establishes an inheritance-based accessibility contract, hiding the implementation from the public API while exposing it to the inheritance hierarchy.
Syntax and Declaration
Theprotected keyword precedes the return type in the method signature. It can be applied to both instance and static methods.
Accessibility Rules and Compiler Behavior
The C# compiler enforces strict rules regarding where and how aprotected method can be invoked. Attempting to access a protected method outside its permitted scope results in compiler error CS0122 ('member' is inaccessible due to its protection level).
- Declaring Class: Fully accessible.
- Derived Class (Same Assembly): Accessible.
- Derived Class (Different Assembly): Accessible.
- Non-Derived Class (Any Assembly): Inaccessible.
The Instance Access Restriction (CS1540)
A critical rule of theprotected modifier is that within a derived class, a protected base instance method can only be accessed through an instance of the derived class type (or a type further derived from it). It cannot be accessed through an instance of the base class type.
This prevents a derived class from bypassing encapsulation to access the protected members of other, unrelated derived classes that share the same base.
protected static methods can be accessed directly via the base class name from within the derived class.
Compound Access Modifiers
Theprotected keyword can be combined with other access modifiers to alter the Common Intermediate Language (CIL) visibility attributes, creating union or intersection accessibility sets:
protected internal: A union. The method is accessible to any type in the same assembly (internal) OR any derived type in any assembly (protected).private protected: An intersection (introduced in C# 7.2). The method is accessible only to derived types that are ALSO located within the same assembly. It is strictly inaccessible across assembly boundaries.
Polymorphic Modifiers
protected methods fully support C#‘s polymorphic modifiers. They can be marked as virtual, abstract, or override. When overriding a protected method, the derived class must maintain the exact protected access level; it cannot widen the visibility to public or narrow it to private.
Master C# with Deep Grasping Methodology!Learn More





