Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do access modifiers matter for the method Main?

Tags:

c#

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?

like image 878
kiss my armpit Avatar asked Oct 22 '12 16:10

kiss my armpit


1 Answers

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.

like image 192
Anirudh Ramanathan Avatar answered Oct 14 '22 22:10

Anirudh Ramanathan