Do the available access modifiers matter for the method Main? If not, why does Main allow us to specify the modifier? Why does the compiler not prevent us from specifying something that are trivial?
Main being public/private does not affect the CLR calling it at all. The CLR will look for a static method named main (by default, but not necessarily) which is associated with its entry point, without looking at access modifiers.
It only affects the visibility of main to the other functions. Good practice is for Main to not be public since it is not to be called by other methods in your assemblies, only by the CLR.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With