MSDN有言:
Main方法不应为公共方法。
这是为什么?我试了,是可以声明为Public的,只是不知道为什么不应为Public呢?

解决方案 »

  1.   

    MSDN写的should not be public,但是没有写为什么,我觉得Main特殊的函数,无论如何编译器都会认识它的,因此无所谓public或者Private    *      The Main method is the entry point of your program, where the program control starts and ends.
        *      It is declared inside a class or struct. It must be static and it should not be public. (In the example above it receives the default access of private.)
        *      It can either have a void or int return type.
        *      The Main method can be declared with or without parameters.
        *      Parameters can be read as zero-indexed command line arguments.
        *      Unlike C and C++, the name of the program is not treated as the first command line argument.参考:
    http://msdn.microsoft.com/en-us/library/acy3edy3%28VS.80%29.aspx
      

  2.   

    MSDN写的should not be public,但是没有写为什么,我觉得Main特殊的函数,无论如何编译器都会认识它的,因此无所谓public或者Private    *      The Main method is the entry point of your program, where the program control starts and ends.
        *      It is declared inside a class or struct. It must be static and it should not be public. (In the example above it receives the default access of private.)
        *      It can either have a void or int return type.
        *      The Main method can be declared with or without parameters.
        *      Parameters can be read as zero-indexed command line arguments.
        *      Unlike C and C++, the name of the program is not treated as the first command line argument.参考:
    http://msdn.microsoft.com/en-us/library/acy3edy3%28VS.80%29.aspx
      

  3.   

    瞎猜:也许是怕被其他代码调用,反正编译器认识,不如弄成private安全点
      

  4.   

    Java是建议你声明Main函数为Public,所以别太纠结于此点
      

  5.   

    Main是大门,每家每户的大门都应该是私有的吧?
      

  6.   

    一个程序一个mian方法,发现过问题,没研究过
      

  7.   


    同意。我猜msdn上这个描述是来自于许多年前,而且是个“权威”写的,所以也许之后的msdn维护人员备份太低没有人敢(或者没有人有那个闲心)去修改它。
      

  8.   


    没有这个必然性。任何public方法都会经历测试,是否会引起程序崩溃这要由测试说了算。而如果我们写一个什么都不做的空的Main函数并不会让程序崩溃,所以说它就会引擎程序崩溃显然是不成立的(不是真正决定是否崩溃的原因)。同样道理,如果lz测试出来Main声明为public也一样,那么msdn上的措辞显然就经不起测试,就是一个文档方面的bug。
      

  9.   

    MAIN为PUBLIC有没有可能导致程序走迷宫?可能还是为了不被其它任何地方调用才有这样的建议吧。楼主在多个地方调用下MAIN函数看看有没有问题啥