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.