C# Feature โ Top-level statements
Overview
Section titled โOverviewโTop-level statements allow a single file program without explicit Program class or Main method.
Introduced In
Section titled โIntroduced InโC# 9 (2020)
class Program{ static void Main(string[] args) { Console.WriteLine("Hello"); }}
Console.WriteLine("Hello");
Gotchas & Best Practices
Section titled โGotchas & Best Practicesโ- Only one file can contain top-level statements.
- The implicit Main may be async if you use await.