Skip to main content

File-Scoped Namespaces

A C# 10 syntax feature that removes one level of indentation from every file by declaring the namespace for the entire file without braces. Instead of wrapping all code in a namespace { ... } block, you write namespace MyProject.MyFeature; at the top and everything in the file belongs to that namespace.

This will seem trivial until you've maintained a codebase with 500 files, each with one unnecessary level of indentation. Then it will seem like the greatest invention since sliced bread, or at least since sliced indentation.

Why it matters for writers: It's a small quality-of-life feature that adds up across an entire codebase. It's listed here partly to complete the picture of modern C# features referenced elsewhere on the site, and partly as an example of C#'s ongoing effort to reduce ceremony and make the language more approachable: a priority that aligns nicely with making AI tooling accessible to developers who aren't ML specialists and don't want to be.

Related terms: Records · Pattern Matching · Nullable Reference Types