C# › Modern C# Features (Global Usings, File-Scoped Namespaces, Top-Level Statements)

How do global using directives work, and how do you declare one for an entire project?

Intermediate

Answer

Prefixing a 'using' directive with 'global' (either directly in a .cs file, or conventionally in a dedicated GlobalUsings.cs file) makes that namespace available to EVERY file in the project automatically, without needing to repeat the same common 'using' statements (like System, System.Linq) at the top of every single file.
// GlobalUsings.cs
global using System;
global using System.Linq;
global using System.Collections.Generic;

// Any other file in the project can now use List<T>, LINQ, etc. WITHOUT its own 'using' statements
Real-world example Eliminating repetitive boilerplate 'using System; using System.Linq;' lines across every file in a large project.

Common follow-ups: Does the SDK automatically generate any implicit global usings for common namespaces, even without an explicit GlobalUsings.cs file?