In C# 9 we saw how top-level statements can help us reduce ‘wasted’ vertical space…

BUT… reducing ‘wasted’ horizontal space and in particular nesting levels is much more valuable IMHO and in C# 10 (released November 2021) we have file-level namespaces to help with this.
File-level namespaces are definitely one of my favourite features from C# 10 and Milan Jovanović’s example (originally posted on LinkedIn) below shows what they look like…

Another approach to reducing nesting levels is to use guard clauses.
Grab Your Free C# Cheat Sheet!
Download "C# Essentials: A Developer's Cheat Sheet" for key syntax, tips, and quick references. Perfect for developers of all levels!
👉 Download your free copy now!Need Help with Your C# Projects?
We offer expert support and development services for projects of any size. Contact us for a free consultation and see how we can help you succeed.
CONTACT US NOW