> ## 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# Using Static Directive

The `using static` directive imports the static members and nested types of a specific type directly into the current compilation unit or namespace scope. This allows developers to invoke static methods, properties, fields, events, and constants without qualifying them with their declaring type name.

## Syntax

```csharp theme={"dark"}
using static <fully-qualified-type-name>;
```

Unlike a standard `using` directive, which imports all types within a namespace, `using static` targets a specific class, struct, interface, or enum.

## Mechanics and Scope

When the compiler encounters a `using static` directive, it modifies the name resolution rules for the current file or namespace block.

**Included Members:**

* **Static Methods, Properties, and Fields:** Accessed directly by their identifier.
* **Constants:** Because `const` fields are implicitly static, they are imported.
* **Nested Types:** Types declared within the target type become accessible without qualification.
* **Enum Members:** When applied to an enumeration, the individual enum values are imported into the local scope.

**Excluded Members:**

* **Instance Members:** The directive strictly ignores instance-level methods, properties, and fields.
* **Extension Methods (Unqualified):** Extension methods declared in the target type are brought into scope for *extension method invocation* (e.g., `object.ExtensionMethod()`), but they are **not** imported for unqualified static invocation. To call them as standard static methods, the type name must still be provided.

## Code Visualization

```csharp theme={"dark"}
using System;
using static System.Math;
using static System.Console;
using static System.DayOfWeek;

namespace DirectiveDemonstration
{
    class Program
    {
        static void Main()
        {
            // 'WriteLine' is resolved from System.Console
            WriteLine("Demonstrating using static");

            // 'PI' and 'Pow' are resolved from System.Math
            double area = PI * Pow(5, 2);

            // 'Monday' is resolved from System.DayOfWeek enum
            DateTime nextMeeting = GetNextDay(Monday); 
        }

        static DateTime GetNextDay(DayOfWeek day) => DateTime.Now;
    }
}
```

## Name Resolution and Ambiguity Rules

The C# compiler enforces strict precedence rules to handle naming collisions when `using static` is employed:

1. **Local Precedence:** Members declared within the current type always take precedence over members imported via `using static`. If a local method and an imported static method share the same signature, the compiler binds to the local method.
2. **Ambiguous Invocation:** If multiple `using static` directives import members with identical names and signatures from different types, the compiler does not raise an error at the directive declaration. However, if that ambiguous member is invoked, the compiler throws error **CS0121** (The call is ambiguous between the following methods or properties). The invocation must then be explicitly qualified with the type name.

## Global Modifier (C# 10+)

The `using static` directive can be combined with the `global` modifier to apply the static import across all compilation units within the project.

```csharp theme={"dark"}
global using static System.Math;
```

When declared globally, the static members of the specified type are injected into the root scope of the entire assembly, subjecting the entire project to the same name resolution and ambiguity rules described above.

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