Skip to content

C# Feature โ€“ Top-level statements

Top-level statements allow a single file program without explicit Program class or Main method.

C# 9 (2020)

class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello");
}
}
Console.WriteLine("Hello");
  • Only one file can contain top-level statements.
  • The implicit Main may be async if you use await.