C# 10 introduces file scoped namespaces. This allows you to remove the ‘{}’ when your source file only has one namespace(like most files typically have).
So instead of writing:
you can now write:
To apply this for an existing project written in C# 9 or lower, you can do this in one go.
Therefore set the language version of your project to C# 10:
Now we need to update our .editorconfig file and add the following line:
After doing that Visual Studio will help us out and we can use “Fix all occurences in Solution” to apply it in one go: