> ## 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# Namespace Declaration

A namespace declaration defines a named declarative region used to establish a hierarchical scope for types. It acts as a logical container that prevents naming collisions by appending a unique prefix to the fully qualified names of the types (classes, interfaces, structs, enums, and delegates) defined within it.

## Block-Scoped Namespace Declaration

The traditional method of declaring a namespace uses the `namespace` keyword followed by a valid C# identifier and a set of curly braces `{ }`. All types declared within the braces belong to that namespace.

```csharp theme={"dark"}
namespace Company.Product.Module
{
    class Component
    {
        // Fully qualified name: Company.Product.Module.Component
    }
}
```

## File-Scoped Namespace Declaration (C# 10+)

File-scoped namespace declarations eliminate indentation by applying the namespace to all types within the file. It is declared using the `namespace` keyword, the identifier, and a terminating semicolon `;`.

```csharp theme={"dark"}
namespace Company.Product.Module;

class Component
{
    // Fully qualified name: Company.Product.Module.Component
}

interface IService
{
    // Fully qualified name: Company.Product.Module.IService
}
```

**Rules for File-Scoped Namespaces:**

* A file can contain only one file-scoped namespace declaration.
* The declaration must precede any type declarations in the file.
* It cannot be combined with block-scoped namespace declarations in the same file.

## Nested Namespace Declarations

Namespaces can be nested to create a deeper hierarchy. This can be achieved either through nested blocks or, more commonly, using dot notation.

**Using Dot Notation (Preferred):**

```csharp theme={"dark"}
namespace Root.Parent.Child
{
    class Node { }
}
```

**Using Nested Blocks:**

```csharp theme={"dark"}
namespace Root
{
    namespace Parent
    {
        namespace Child
        {
            class Node { }
        }
    }
}
```

## Technical Characteristics and Constraints

* **Implicit Access:** Namespaces are implicitly `public`. You cannot apply access modifiers (such as `public`, `private`, or `internal`) to a namespace declaration.
* **Compiler Merging:** Namespace declarations are open-ended. If you declare the same namespace in multiple files, or multiple times within the same file, the C# compiler merges the members into a single namespace during compilation.
* **Global Namespace:** Any type declared outside of a specific namespace declaration belongs to the implicit "global" namespace. You can explicitly reference the global namespace using the `global::` alias qualifier (e.g., `global::System.String`).
* **Valid Identifiers:** Namespace names must adhere to standard C# identifier rules (e.g., cannot start with a number, cannot be a reserved keyword unless prefixed with `@`).

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