AlgoMaster Logo

File-Scoped Namespaces

Medium Priority17 min readUpdated June 6, 2026

C# 10 introduced a shorter way to declare the namespace for a file. Instead of wrapping every type in a namespace Foo { ... } block that adds an extra indent level to the whole file, you write namespace Foo; on its own line near the top, and every type that follows belongs to that namespace automatically. This lesson covers the syntax, the rules and limitations, why the .NET project templates switched to it by default in .NET 6, and how to migrate an existing codebase.

Premium Content

Subscribe to unlock full access to this content and more premium articles.