Glossary / global using

global using

A global using directive makes a namespace or static type available throughout a compilation without repeating using in each file. It reduces repetitive imports, but also introduces implicit dependencies that can make an individual file's required namespaces less visible.

Syntax and scope

global using System.Text;
global using static System.Math;
global using Alias = MyCompany.Common;

Global usings were introduced in C# 10. They apply across the compilation, not across arbitrary assemblies or projects. They can be declared in source or generated by SDK settings such as implicit usings. Duplicate compatible directives are generally harmless, while alias conflicts or namespace collisions can create ambiguity. File-scoped ordinary usings remain local to that file.

Implicit usings are SDK/project configuration, often enabled for common templates, and differ by SDK/project type. A file may compile in one project due to implicit/global imports but fail when moved to another. Generated global usings may be found under obj build output.

Engineering guidance

Use a small, predictable set of global imports for ubiquitous namespaces. Keep domain-specific and ambiguous namespaces local. Document implicit usings in project configuration and ensure standalone source files or analyzers account for them. Avoid aliases that obscure where types come from.

Interview questions

  1. What is the scope of global using? All source files in the same compilation.
  2. Does it cross project boundaries? No.
  3. What are implicit usings? SDK-generated global directives based on project SDK/settings.
  4. Why can moving a file break it? It may rely on project-level imports absent in the new compilation.
  5. When keep using local? For less common or ambiguous namespaces that should remain visible at file level.

References