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

The `using` alias directive creates a user-defined identifier for an existing namespace or type. It instructs the C# compiler to substitute the alias with the target namespace or type during the compilation process. This substitution is strictly a compile-time mechanism; aliases do not create new types and do not exist in the emitted Intermediate Language (IL).

## Syntax

```csharp theme={"dark"}
using alias_name = namespace_or_type_name;
```

## Scope and Modifiers

* **Compilation Unit Scope:** When declared at the top of a file, preceding any namespace or type declarations, the alias is scoped to the entire compilation unit (the specific source file).
* **Namespace Scope:** When declared inside a block-scoped `namespace { ... }` declaration, the alias is scoped only to that specific namespace body. It must be placed at the top of the namespace body, before any type or nested namespace declarations.
* **Global Scope (C# 10+):** Applying the `global` modifier extends the alias to the entire compilation (all compilation units within the project or assembly). Global aliases must precede any non-global `using` directives.

```csharp theme={"dark"}
global using alias_name = namespace_or_type_name;
```

## Resolution Rules

The right-hand side of the alias assignment is resolved relative to the declaration space containing the `using` directive. It is resolved as if the containing file or namespace had no other `using` directives to assist in resolution. It does not need to be fully qualified from the root namespace, but it cannot implicitly rely on imported namespaces.

```csharp theme={"dark"}
// Invalid: Cannot rely on a separate 'using System.Collections.Generic;'
// using StringMap = Dictionary<string, string>; 

// Valid: Explicitly pathed because it cannot rely on other using directives
using StringMap = System.Collections.Generic.Dictionary<string, string>;

namespace MyCompany.Core
{
    // Valid: Resolves relative to the MyCompany.Core declaration space.
    // Must precede all other elements (like namespaces or classes) in the body.
    using LogUtil = Utilities.Logger;

    namespace Utilities
    {
        class Logger { }
    }
}
```

## Supported Alias Targets

**1. Namespace Aliasing**
Maps an identifier to a specific namespace hierarchy.

```csharp theme={"dark"}
using NetHttp = System.Net.Http;
```

**2. Constructed Type Aliasing**
Maps an identifier to a specific, fully constructed type. Open generics (e.g., `List<>`) cannot be aliased.

```csharp theme={"dark"}
using UserCache = System.Collections.Concurrent.ConcurrentDictionary<int, string>;
```

**3. Any Type Aliasing (C# 12+)**
Starting in C# 12, the directive supports aliasing virtually any valid C# type, including tuples, arrays, pointer types, and function pointers.

```csharp theme={"dark"}
// Tuple alias
using Point3D = (double X, double Y, double Z);

// Array alias
using Matrix = double[][];

// Unsafe pointer alias
using IntPointer = int*;

// Function pointer alias
using ActionDelegate = delegate*<int, void>;
```

## The Namespace Alias Qualifier (`::`)

When an alias shares a name with a locally declared type or namespace, the compiler may encounter an ambiguity error. The namespace alias qualifier operator (`::`) forces the compiler to resolve the identifier specifically against the defined alias rather than the local scope.

```csharp theme={"dark"}
using Sys = System;

class Program
{
    static void Main()
    {
        // Forces resolution through the 'Sys' alias
        Sys::Console.WriteLine("Resolved via alias qualifier.");
    }
}
```

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