top-level statements
C# code written directly at the top of Program.cs, without a class or Main method, from which the compiler generates the program's entry point.
In more detail
Only one file in a project may use them, and they must come before any type declarations in that file. They are ordinary compiled C#, not a scripting mode: you can declare variables, call methods and use await.
Related terms
- entry point — The first file or function that runs when a program starts.
- Program.cs — The source file where a .NET application starts, usually holding top-level statements that build and run the host.
- boilerplate — Repetitive code that has to be written the same way every time and adds little meaning of its own.
Taught in
- What is .NET? Runtime vs SDK, and LTS vs STS — Modern .NET Core, C# & Enterprise Microservices
- Records, Pattern Matching, and Modern C# — Modern .NET Core, C# & Enterprise Microservices