Why STATIC keyword in C# main () method is Used?

(Last Updated On: February 26, 2019)

Answer: Static keyword in C# main () method is used, so that compiler can call it without or before creation of an object.

 

Actually, main () method is the default starting point of execution of a program that compiler calls. And compiler must hit main () to execute the program first. Now, the question is how compiler is going to call main () method that resides within a class. We know that a method in a class must be called by an object if method is not static or if method is static, it can be called by using class name and object creation is not required.

 

Recommended to read static and non-static method call in C# Program

 

Since, compiler has to call main () method first, it cannot create object of the class “Program” before main (), as execution starts from main and before that object creation not possible. So, there is only option is to make the main () method static.

Static method call – C# program example