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

A partial method is a method declared within a `partial` type (class, struct, interface, or record) where the method signature is defined in one part of the type, and its implementation is provided in another part.

The `partial` keyword instructs the compiler to merge the signature and the implementation during the compilation process.

```csharp theme={"dark"}
using System;

// File1.cs - Declaration
public partial class DataProcessor
{
    // Method signature
    partial void InitializeProcessing();

    public void Start()
    {
        InitializeProcessing(); // Invocation site
    }
}

// File2.cs - Implementation
public partial class DataProcessor
{
    // Method implementation
    partial void InitializeProcessing()
    {
        Console.WriteLine("Initialization complete.");
    }
}
```

## Compiler Behavior and Rules

The rules governing partial methods depend entirely on whether an explicit access modifier is applied to the method signature. C# 9.0 introduced "Extended Partial Methods," creating two distinct sets of constraints.

### 1. Implicitly Private Partial Methods (Pre-C# 9.0 Behavior)

If a partial method is declared **without** an explicit access modifier, it is subject to strict limitations:

* **Access Level:** It is implicitly `private`.
* **Return Type:** It must return `void`.
* **Parameters:** It cannot contain `out` parameters (though `ref` and `in` are permitted).
* **Modifiers:** It cannot be marked as `virtual`, `override`, `sealed`, `new`, or `extern`.
* **IL Erasure:** If no implementation is provided in any part of the partial type, the compiler completely removes the method signature and all invocation sites from the emitted Intermediate Language (IL). No runtime overhead is incurred for unimplemented partial methods.

### 2. Extended Partial Methods (C# 9.0+)

If a partial method is declared **with** an explicit access modifier (including `private`), the compiler treats it as an extended partial method, lifting the strict constraints but enforcing implementation:

* **Access Level:** Can use any access modifier (`public`, `internal`, `protected`, `private`, etc.).
* **Return Type:** Can return any type, including `void`.
* **Parameters:** Can contain `out` parameters.
* **Mandatory Implementation:** Because the method might return a value, have `out` parameters, or be invoked externally, the compiler **requires** an implementation. If the implementation is missing, the compiler throws a build error (`CS8795`).

```csharp theme={"dark"}
// File1.cs - Declaration with access modifier and return type
public partial class DataProcessor
{
    // Because it is public and returns a string, it MUST be implemented
    public partial string GetProcessorState(out int statusCode);
}

// File2.cs - Implementation
public partial class DataProcessor
{
    public partial string GetProcessorState(out int statusCode)
    {
        statusCode = 200;
        return "Active";
    }
}
```

## Signature Matching Requirements

When providing the implementation for a partial method, the structural signature must exactly match the declaration. This includes:

* Method name.
* Return type.
* Access modifiers.
* Parameter types and modifiers (`ref`, `in`, `out`, `params`).
* The number of generic type parameters and their constraints.

**Naming Exceptions:**
Parameter names and generic type parameter names do **not** need to match between the declaration and the implementation. The names defined in the defining declaration are exposed to callers (e.g., for named arguments), while the names defined in the implementation are used locally within the method body.

Attributes applied to the method declaration and the method implementation are merged by the compiler into a single attribute set in the final compiled assembly.

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