TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
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
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
globalmodifier extends the alias to the entire compilation (all compilation units within the project or assembly). Global aliases must precede any non-globalusingdirectives.
Resolution Rules
The right-hand side of the alias assignment is resolved relative to the declaration space containing theusing 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.
Supported Alias Targets
1. Namespace Aliasing Maps an identifier to a specific namespace hierarchy.List<>) cannot be aliased.
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.
Master C# with Deep Grasping Methodology!Learn More





