Why is the Main() method 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. The Main() method is static because it’s 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. In other words, static functions exist before a class is instantiated, so static is applied to the main entry point.

No comments:

Post a Comment