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

A static method in C# is a member that belongs to the type itself rather than to a specific object instance. Declared using the `static` modifier, it is resolved via early binding (compile-time) and is invoked directly through the class name, meaning no object instantiation is required for execution.

## Syntax and Invocation

```csharp theme={"dark"}
public class Calculator
{
    // Declaration using the static modifier
    public static int Add(int x, int y)
    {
        return x + y;
    }
}

// Invocation routes through the type, not an object reference
int sum = Calculator.Add(5, 10);
```

## Architectural and Lexical Rules

* **State Access:** A static method operates in a strictly static context. It can only directly access other static fields, properties, and methods within its class. It cannot access instance members, as no implicit object reference is passed to the method signature.
* **Keyword Restrictions:** Because a static method is not bound to an instance, the `this` and `base` keywords cannot be used as implicit instance references within the method body. The `this` keyword is only permitted within the method's parameter signature when explicitly defining an Extension Method.
* **Polymorphism:** In standard classes, static methods do not support runtime polymorphism (late binding) and cannot be marked as `virtual`, `abstract`, or `override`. A derived class can only hide a base class static method using the `new` keyword (member shadowing). However, as of C# 11, interfaces can declare `static abstract` and `static virtual` methods. This enables static polymorphism across generic type parameters, a feature heavily utilized by modern .NET generic math.
* **Overloading:** Static methods can be overloaded by altering the method signature (parameter types, count, or order).
* **Thread Safety:** The execution of the method itself is thread-safe if it is purely functional (stateless). However, if the static method mutates static fields, that state is shared across all threads within the application process or load context, requiring explicit synchronization mechanisms (e.g., `lock`, `Interlocked`) to prevent race conditions.

## CLR and Memory Mechanics

When the Common Language Runtime (CLR) loads a type into an `AssemblyLoadContext` (in modern .NET Core/.NET 5+) or an `AppDomain` (in legacy .NET Framework), it allocates a Type Object in the High-Frequency Heap. Static methods are associated with this Type Object rather than being duplicated across individual object instances. The JIT (Just-In-Time) compiler generates the native code for the static method once per isolation boundary, and all invocations route to this single memory address.

## Extension Methods Infrastructure

Static methods serve as the underlying compiler infrastructure for C# Extension Methods. When a static method is declared inside a top-level, non-generic `static` class and its first parameter is prefixed with the `this` modifier, the compiler emits metadata (the `[Extension]` attribute) that allows the method to be invoked using instance-method syntax.

```csharp theme={"dark"}
public static class StringExtensions
{
    // Static method acting as an extension method
    public static int WordCount(this string text)
    {
        return text.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Length;
    }
}

// The compiler translates this instance-syntax call into: 
// StringExtensions.WordCount(message);
string message = "Hello World";
int count = message.WordCount(); 
```

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