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

The `using` directive in C# instructs the compiler to resolve unqualified type names by searching specified namespaces. It brings the types contained within a namespace into the current lexical scope, eliminating the requirement to write fully qualified type names (e.g., writing `List<T>` instead of `System.Collections.Generic.List<T>`).

*Note: The `using` directive is strictly a scope and naming resolution mechanism and is distinct from the `using` statement, which is used for deterministic disposal of `IDisposable` objects.*

The directive operates in the following syntactical forms and mechanisms:

## 1. Standard Namespace Import

Imports all accessible types from a specified namespace into the current scope. It does not recursively import nested namespaces; each namespace must be explicitly declared.

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

## 2. Static Import (`using static`)

Imports the static members and nested types of a specific type (which includes classes, structs, interfaces, and enums) directly into the current scope. This allows the invocation of static methods, properties, or enum values without qualifying them with their declaring type name.

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

double radius = 5.0;
// 'PI' is resolved directly from System.Math
double area = PI * radius * radius;

// 'Red' is resolved directly from System.ConsoleColor
System.Console.ForegroundColor = Red;
```

## 3. Alias Directive

Creates a local identifier (alias) for a fully qualified namespace or type. This is the primary mechanism for resolving naming collisions when identical type names exist in multiple imported namespaces, or for shortening complex generic type signatures.

```csharp theme={"dark"}
// Type alias
using StringMap = System.Collections.Generic.Dictionary<string, string>;

// Namespace alias
using WinUI = System.Windows.Controls;
```

## 4. Global Modifier (`global using`)

Introduced in C# 10, appending the `global` modifier applies the `using` directive to the entire compilation (the project or assembly), rather than restricting it to the current compilation unit (a single source file).

```csharp theme={"dark"}
global using System.Linq;
global using static System.Math;
global using JsonMap = System.Text.Json.Nodes.JsonObject;
```

## 5. Implicit Usings

Implicit usings are an MSBuild/.NET SDK feature. They are controlled via the `.csproj` file:

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

When enabled, the SDK automatically generates a hidden C# source file during the build process containing `global using` directives for foundational namespaces based on the project SDK type (e.g., Console, Web). The C# compiler itself has no concept of implicit usings; it simply compiles the SDK-generated file alongside the rest of the source code, removing the need to explicitly declare those namespaces in individual source files.

## Scope and Resolution Rules

* **Placement:** `using` directives must precede any member declarations within their enclosing declaration space. They are not strictly required to be at the top of a file; they simply must appear before any type or namespace declarations within that specific file scope or namespace body.
* **Namespace-level Scope:** A `using` directive can be placed inside a `namespace` block. When declared this way, its scope is restricted exclusively to that specific namespace declaration.
* **Global Placement:** `global using` directives must precede all non-global `using` directives in a compilation unit.
* **Ambiguity:** If an unqualified type exists in multiple imported namespaces, the compiler does not prioritize one over the other. Instead, it emits an ambiguous reference error (CS0104). The developer must resolve this by using a fully qualified name or defining a `using` alias.

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