> ## 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 Method

A private method in C# is a member function declared with the `private` access modifier, restricting its visibility and invocation strictly to the containing type (`class`, `struct`, `record`, or `interface`). It represents the most restrictive access level in the C# type system, enforcing strict encapsulation by hiding the method's signature and implementation from external types, derived classes, and other assemblies.

```csharp theme={"dark"}
public class TargetClass
{
    // Explicitly private method
    private int CalculateHash(string input)
    {
        return input.GetHashCode();
    }

    // Implicitly private method (default behavior in classes/structs/records)
    void FormatData()
    {
        // Implementation
    }

    // Type-bound access demonstration
    public void CompareHash(TargetClass otherInstance)
    {
        // Valid: Accessing a private method on a different instance of the EXACT SAME type
        int otherHash = otherInstance.CalculateHash("data"); 
    }
}
```

## Access Rules and Scope

* **Containing Type:** Fully accessible by any other method, property, event, or constructor defined within the exact same `class`, `struct`, `record`, or `interface`.
* **Type-Bound Access:** The `private` modifier in C# is type-bound, not instance-bound. Code executing within a type can freely invoke private methods on *other* instantiated objects of that exact same type.
* **External Invocation:** Attempting to invoke a private method on an instantiated object from *outside* the declaring type (e.g., `obj.CalculateHash("data")` called from a different class) results in compiler error CS0122 due to its protection level.
* **Derived Types:** Inaccessible to types that inherit from the containing class or record. If a derived type requires access, the base method must be marked `protected` instead.
* **Nested Types:** Accessible to nested types defined within the containing type. A nested type implicitly shares the access context of its declaring parent type.

## Technical Characteristics

* **Implicit Default:** If a method declaration within a `class`, `struct`, or `record` omits an access modifier, the C# compiler implicitly assigns it the `private` access level. Conversely, interface members default to `public`, meaning private methods within an `interface` (supported since C# 8.0) must explicitly declare the `private` keyword.
* **Polymorphism Restrictions:** Private methods cannot participate in inheritance-based polymorphism. They cannot be declared with `virtual`, `abstract`, or `override` modifiers because their restricted scope prevents derived classes from seeing them to provide an overridden implementation.
* **IL and Binding:** Invocations of private methods are resolved at compile-time (early binding). Because they cannot be overridden, the compiler typically emits a `call` instruction rather than a `callvirt` instruction in the Common Intermediate Language (CIL), which avoids virtual method table (vtable) lookups.
* **Reflection Bypass:** While the C# compiler strictly enforces private access restrictions during compilation, private methods can still be discovered and invoked dynamically at runtime using the .NET Reflection API by utilizing `BindingFlags.NonPublic | BindingFlags.Instance` (or `BindingFlags.Static` for static private methods).

<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>
