4

I reading the Microsoft C# guide, I feel very confused.

http://msdn.microsoft.com/en-us/library/acy3edy3(v=vs.100).aspx

On this page, a statement says Main should not be public?

Main is declared inside a class or struct. Main must be static and it should not be public. (In the earlier example, it receives the default access of private.) The enclosing class or struct is not required to be static.

I feel very confused because I can compile and run by

public static void Main

And In my general understand on C++, Java, Main can be public.
Is the MSDN article has typo?

mxmissile
  • 11,464
  • 3
  • 53
  • 79
  • 2
    "should" just means it's a guideline. Here's some reasoning why: http://stackoverflow.com/questions/3110184/why-is-main-method-private – Dirk Vollmar Dec 03 '12 at 09:41
  • Bizarre that this is their guideline but their IDE defaults to ignoring it. – Rawling Dec 03 '12 at 09:43
  • @0xA3 Thats correct. Main shouldn't ever be called by the user, thus it'd be a good idea to make it as encapsulated or "hidden" as possible –  Dec 03 '12 at 09:43

1 Answers1

2

I feel very confuse because I can compile and run by

Its a guideline not a rule, so compiler has nothing to do with it.

Habib
  • 219,104
  • 29
  • 407
  • 436
  • I agree it is just a guideline, is it only to prevent user to call the Main function later ? – AlexH Dec 03 '12 at 09:45
  • @AlexH, YES, making it public will make the method accessible outside the assembly. – Habib Dec 03 '12 at 09:48
  • 5
    @AlexH, here is a good discussion about it. http://social.msdn.microsoft.com/Forums/en-CA/csharpgeneral/thread/9184c55b-4629-4fbf-ad77-2e96eadc4d62 – Habib Dec 03 '12 at 09:49