C# 9.0 Features – Top level statements

Top level statements allows us to simplify code by removing boiler plate code that gets generated by default.

For example, when we generate a new Console app traditionally, we can see a Program.cs as follows

This is further simplified in C# 9.0 by using Top level statements as follows:

The namespace, class and Main method declaration is the default boiler plate code for Program.cs and is skipped. It is called Top level as the code is written on the top level in place of namespace declaration.

In fact the new Console Template project creates the Program.cs with the top level statements.

Refer C# Features list for other related posts