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

A static class in C# is a class declared with the `static` modifier that cannot be instantiated and is strictly limited to containing only static members and constant values. It serves as a structural container for state and behavior that is bound directly to the type itself, rather than to any specific object instance.

```csharp theme={"dark"}
public static class StaticClassName
{
    // Fields, properties, methods, and events must be explicitly static
    public static int StaticField;
    
    // Constants are implicitly static and are permitted
    public const string Version = "1.0.0";
    
    public static void StaticMethod() 
    { 
        // Implementation
    }

    // Nested types do not require the static modifier
    public class NestedClass { }
    public enum NestedEnum { OptionA, OptionB }
}
```

## Core Architectural Rules

* **Instantiation:** The compiler strictly prohibits the use of the `new` operator on a static class. Attempting to instantiate it results in compile-time error CS0712.
* **Inheritance:** Static classes are implicitly `sealed`. They cannot be inherited by any other class. Furthermore, they cannot inherit from any class other than `System.Object`, and they cannot implement interfaces.
* **Member Restrictions:** Every field, property, method, and event within a static class must explicitly include the `static` modifier. The inclusion of any instance member triggers a compile-time error. However, there are two critical exceptions regarding type members:
  * **Constants:** `const` fields are implicitly static and are permitted. Explicitly applying the `static` modifier to a `const` field results in compile-time error CS0106.
  * **Nested Types:** Nested types (classes, structs, enums, delegates, and interfaces) do not require the `static` modifier. Furthermore, nested structs, enums, and interfaces are perfectly valid inside a static class but cannot be marked `static` at all.
* **Extension Methods:** Static classes are the only architectural construct in C# capable of hosting Extension Methods (methods defined with the `this` modifier on the first parameter). To host extension methods, the static class must be **non-generic** and **non-nested**.

## Constructor Constraints

Static classes cannot contain instance constructors. They are permitted to have a single static constructor, subject to the following constraints:

* It must be parameterless.
* It cannot have access modifiers (e.g., `public`, `private`).
* It is invoked automatically by the Common Language Runtime (CLR) exactly once per Application Domain (AppDomain), strictly before any static member is referenced.

```csharp theme={"dark"}
public static class ApplicationState
{
    public static readonly string StartupTime;

    // Static constructor
    static ApplicationState()
    {
        StartupTime = System.DateTime.UtcNow.ToString("O");
    }

    public static void RegisterState()
    {
        // Method logic
    }
}
```

## Memory Allocation and Lifecycle

When a C# application executes, the type object for a static class is loaded into the High-Frequency Heap of the AppDomain. Because there are no instances, memory is allocated only for the static fields defined within the class.

The lifecycle of a static class and its state is intrinsically tied to the AppDomain. The CLR initializes the class upon first access, and the memory allocated for its static fields is not eligible for garbage collection until the AppDomain itself is unloaded. Consequently, state held within a static class is globally accessible and persists for the lifetime of the application.

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