

Main must be static and it need not be public.

Main is declared inside a class or struct.The Main method is the entry point of an executable program it is where the program control starts and ends.Starting in C# 9, you can omit the Main method, and write C# statements as if they were in the Main method, as in the following example:įor information about how to write application code with an implicit entry point method, see Top-level statements. Display the number of command line arguments. For more information, see StartupObject (C# Compiler Options). If you have more than one class that has a Main method, you must compile your program with the StartupObject compiler option to specify which Main method to use as the entry point. There can only be one entry point in a C# program. (Libraries and services do not require a Main method as an entry point.) When the application is started, the Main method is the first method that is invoked. The Main method is the entry point of a C# application.
