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

The `global using` directive, introduced in C# 10, instructs the compiler to apply a namespace import, static import, or alias across all source files within an entire compilation unit. By defining a dependency globally, the specified namespace or type becomes implicitly available to every `.cs` file in the project during the compilation process.

## Syntax Variations

The `global` modifier can be applied to all three standard forms of the `using` directive:

```csharp theme={"dark"}
// 1. Standard namespace import
global using System.Collections.Generic;

// 2. Static import (imports static members of a specific type)
global using static System.Console;

// 3. Aliasing (creates a global alias for a namespace or type)
global using JsonDict = System.Collections.Generic.Dictionary<string, System.Text.Json.JsonElement>;
```

## Lexical Placement and Rules

To ensure successful compilation, `global using` directives are subject to strict ordering rules within the source file they inhabit:

1. **Top-Level Precedence:** A `global using` directive must precede all non-global `using` directives, `namespace` declarations, and type definitions within the file.
2. **File Independence:** The directive can be placed in any `.cs` file within the project. The compiler aggregates all global usings across the compilation unit before resolving types.
3. **Redundancy Handling:** If a namespace is imported globally, declaring a standard `using` directive for the same namespace in an individual file is syntactically valid but redundant; the compiler will safely ignore the duplicate.

**Valid Ordering:**

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

using System.IO; // Non-global must come after global

namespace ApplicationCore;
// Type definitions follow...
```

**Invalid Ordering (Compilation Error CS8915):**

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

global using System.Text; // Error: global using must precede non-global using
```

## MSBuild Integration (Implicit Usings)

The .NET SDK leverages the `global using` feature at the build level via the `<ImplicitUsings>` property in the `.csproj` file.

```xml theme={"dark"}
<PropertyGroup>
  <ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
```

When enabled, the MSBuild process automatically generates a file named `<ProjectName>.GlobalUsings.g.cs` in the `obj/Debug/netX.0/` directory. This auto-generated file contains a predefined set of `global using` directives based on the project's SDK type (e.g., `Microsoft.NET.Sdk` vs `Microsoft.NET.Sdk.Web`), injecting foundational namespaces into the compilation unit without requiring manual source code declarations.

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