The Main method is the entry point of a C# console application or windows application. When the application is started, the Main method is the first method that is invoked. This Main() method is present in every executable application. Executable means any Console application, Windows desktop application or Windows service application.

There can only be one entry point in a C# program. If you have more than one class that has a Main method, you must compile your program with the /main compiler option to specify which Main method to use as the entry point.
So,

Main method define as Static

Static members are scoped to the class level (rather than the object level) and can thus be invoked without the need to first create a new class instance. A main method is static because it is available to run when your program starts and as it is the entry point of the program it runs without creating an instance of the class.

FAQ related to this article

  1. Can we have more than one main method in a class?

    Yes, in .NET, an executable can have only one entry point i.e. only one Main method is allowed. Main method is considered as an entry point only if the signature would be static Main(String[]) or static Main(), If you provide any main method whose signature is different from both method mention above, it is not considered as Main method (entry point). So, below code is allowed,
    1. class Program
    2. {
    3. static void Main () //Entry point
    4. {
    5. }
    6. static void Main(int number)
    7. {
    8. }
    9. }
    The below code doesn't compile because it finds matching signature at two places.
    1. class Program
    2. {
    3. static void Main () //Entry point
    4. {
    5. }
    6. static void Main(String[] args) //another entrypoint!!! Compile Error
    7. {
    8. }
    9. }
    Below code also doesn't compile because there is no entry point at all,
    1. class Program
    2. {
    3. static void Main (int a) //Not an Entry point
    4. {
    5. }
    6. static void Main(float b) //Not an entry point
    7. {
    8. }
    9. }
  2. Can we overload the main method?

    Yes, but only one method would be treated as an entry point. We have already one entry point in that class then other method should not be static Main(String[]) or static Main().

  3. Can we override the main method?

    No, you cannot override the main method because it is a static method and static method can’t be virtual or abstract.

  4. Can we have more than one main method in a program/.exe?

    Yes,If more one class that has a Main method in any .exe, then you must compile your program with the /main compiler option to specify which Main method to use as the entry point.

    csc filename.cs /main:

    <className>