> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# C# Private Protected Field

The `private protected` access modifier restricts member visibility to the containing class and types derived from that class, strictly provided they reside within the same assembly. Introduced in C# 7.2, it acts as a logical AND operation between the `internal` (same assembly) and `protected` (derived types) modifiers, making it more restrictive than either modifier individually.

```csharp theme={"dark"}
public class BaseClass
{
    private protected int _stateValue;
}
```

## Access Mechanics

To access a `private protected` field, the consuming type must satisfy **both** of the following conditions simultaneously:

1. **Inheritance:** The consuming type must inherit from the class declaring the field.
2. **Location:** The consuming type must be compiled into the exact same assembly as the declaring class.

This contrasts directly with the `protected internal` modifier, which functions as a logical OR operation (accessible if derived *or* in the same assembly).

## Compilation Boundaries

The following code block demonstrates the strict compilation boundaries enforced by the `private protected` modifier across different scopes and assemblies.

```csharp theme={"dark"}
// =========================================
// Assembly A
// =========================================
public class BaseClass
{
    private protected int _coreField;
}

public class DerivedInSameAssembly : BaseClass
{
    public void MutateField()
    {
        // VALID: Type is derived AND resides in Assembly A.
        _coreField = 42; 
    }
}

public class NonDerivedInSameAssembly
{
    public void AttemptMutation(BaseClass instance)
    {
        // ERROR CS0122: '_coreField' is inaccessible due to its protection level.
        // Fails condition: Not a derived type.
        instance._coreField = 42; 
    }
}

// =========================================
// Assembly B (References Assembly A)
// =========================================
public class DerivedInDifferentAssembly : BaseClass
{
    public void AttemptMutation()
    {
        // ERROR CS0122: '_coreField' is inaccessible due to its protection level.
        // Fails condition: Resides in Assembly B, not Assembly A.
        _coreField = 42; 
    }
}
```

## CLR Implementation

At the Common Intermediate Language (CIL) level, the `private protected` modifier is represented by the `famandassem` accessibility attribute. This instructs the Common Language Runtime (CLR) to enforce the intersection of `family` (protected) and `assembly` (internal) visibility rules during Just-In-Time (JIT) compilation and execution.

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor C# Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
