The question here is not about static functions, but specifically why is main
static in a C#
application.
It has to do with having only one thread for the main application. This is defined when using the [STAThread]
attribute on the main function. The executing thread enters the main function only once, and no instance of the Program
class is required.
The static main function can then instantiate any classes it requires for normal operation. These are often things like forms, or worker classes.
The program either enter a message loop in the main thread to process a visible form, or the program terminates.
When you remove the static reference for main the build options
for the project switch from a startup function
to a startup object
, and an instance of the class is created before main
is called.
It's a matter of personal preference, but keep in mind that only 1 main is ever executed during start up.