Main method entry point with string argument gives “does not contain … suitable … entry point” error

前端 未结 5 883
死守一世寂寞
死守一世寂寞 2021-01-12 11:15

Why does the code block below give a compile error of \"does not contain a static \'Main\' method suitable for an entry point\"?

namespace MyConApp
{
    cla         


        
相关标签:
5条回答
  • 2021-01-12 11:37

    The signature of the main method must be main(String[]), not main(String).

    0 讨论(0)
  • 2021-01-12 11:44

    See this to understand Main method signature options.

    0 讨论(0)
  • 2021-01-12 11:50

    Because the argument is String and not a String Array as expected

    0 讨论(0)
  • 2021-01-12 11:52

    The only valid signatures for Main method are :

    static void Main()
    

    and

    static void Main(string[])
    

    static void Main(string) is not a valid signature for Main method.

    0 讨论(0)
  • 2021-01-12 11:56

    In the code you provide the problem is that the 'Main' entry point is expecting a array of strings passed from system when the program is invoked (this array can be null, has no elements)

    to correct change

    static void Main(string args) 
    

    to

    static void Main(string[] args) 
    

    You could get the same error if you declared your 'Main' of any type other than 'void' or 'int'

    so the signature of the 'Main' method has always to be

    static // ie not dynamic, reference to method must exist
    public // ie be accessible from the framework invoker
    Main   // is the name that the framework invoker will call
    
    string[] <aName> // can be ommited discarding CLI parameters
    * is the command line parameters space break(ed)
    

    From MS (...) The Main method can use arguments, in which case, it takes one of the following forms:

    static int Main(string[] args)
    static void Main(string[] args)
    
    0 讨论(0)
提交回复
热议问题