C# entry point function

Before C# 9, the entry point had to be declared explicitly. C# 9 introduces top level statements which allow the entry point to be generated implicitly. (Only a single source file in a project can include top-level statements, however.)

When the entry point is declared explicitly, it has to be Main. It’s static because otherwise the CLR would need to worry about creating an instance of the type – which means you’d presumably have to have a parameterless constructor, even if you didn’t want an instance of the type, etc. Why would you want to force it to be an instance method?

Even with top-level statements, your actual program still has an entry point called Main – it just doesn’t appear in your source code.

Leave a Comment