C# entry point function

Yes, it has to be Main. It's static because otherwise the CLR would need to worry about creating an instance of the type - which means you'd presumably have to have a parameterless constructor, even if you didn't want an instance of the type, etc. Why would you want to force it to be an instance method?


Yes, for a C# application, Main() must be the entry point.

The reason is because that's what the designers of the language decided to be what to look for as an entry point for your program. They could just as well have used a totally different approach to find the entry point, e.g. using meta data, or instantiating an object for you (which would require a parameterless constructor). Another reason for naming it void main() is that it's intuitive for users coming from other languages.


static void Main() is the necessary entry point for any "Executable" (.EXE) to be created in C#. A library (or .DLL) can have other entry points.

The method is static because that is required in order to access the method without having an instance of the object to address. In order to invoke the method (starting point) from outside the application, a static method is required.

Tags:

C#