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.
:: operator, formally known as the namespace alias qualifier, explicitly instructs the C# compiler to resolve an identifier within a specific namespace alias. It overrides the default hierarchical scope resolution rules, guaranteeing that the compiler binds the identifier strictly to the aliased scope and preventing local types or namespaces from shadowing external ones.
Syntax
alias_name: A namespace alias defined via ausingdirective, anextern aliasdirective, or the contextual keywordglobal.identifier: The specific type or child namespace being accessed within the aliased scope.
Mechanics
Unlike the member access operator (.), which navigates down a namespace or object hierarchy based on proximity and standard resolution rules, the :: operator anchors the lookup exclusively to the specified alias. The left-hand side of the :: operator must always be a valid alias; it cannot be a standard namespace name or a type.
Custom Alias Resolution
When a custom alias is defined, the:: operator binds the subsequent identifier directly to the namespace mapped by that alias.
The global Contextual Keyword
The global contextual keyword acts as a predefined alias for the unnamed global namespace of the entire compilation context. This encompasses all referenced assemblies and libraries (such as the .NET Base Class Library), not just the application’s own root namespace.
When global:: is invoked, the compiler bypasses all nested or local scopes and begins its type lookup at the absolute top level of the compilation context. This is necessary when a type declared in a nested declaration space shadows a global namespace.
External Assembly Aliasing (extern alias)
The :: operator is the primary mechanism used in conjunction with the extern alias directive to resolve fully qualified type name collisions between different referenced assemblies. When two assemblies contain the exact same namespace and type, an external alias is assigned to one or both assemblies at the compiler level, and the :: operator routes the lookup to the specific assembly.
Compilation Rules
- Invalid Left-Hand Operand: If the token preceding
::is not a recognizedusingalias,extern alias, orglobal, the compiler emits error CS0432. - Alias Hiding: If a local type shares a name with a namespace alias, the
::operator ensures the alias takes precedence, whereas the.operator would resolve to the local type.
Master C# with Deep Grasping Methodology!Learn More





