Entry point error for Main (string args)?

using System; using System.Collections.Generic; using System.Text;

namespace MyConApp { class Program { static void Main(string[] args) { string[] tmpString; tmpString = args; Console.WriteLine("Hello" + tmpString[0].ToString()); } } } 

Why The expression below shows the compilation error message "does not contain a static" Basic "method suitable for the entry point"

 namespace MyConApp { class Program { static void Main(string args) { string tmpString; tmpString = args; Console.WriteLine("Hello" + tmpString); } } } 

Thanks.

+4
source share
5 answers

See this to understand the signature options of the Main method.

+3
source

Since the argument is a String, not a string array, as expected

+3
source

The only valid signatures for the Main method are:

 static void Main() 

and

 static void Main(string[]) 

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

+3
source

In the code that you specify, the problem is that the Home entry point expects an array of strings passed from the system when the program was called (this array can be null, contain no elements)

to correct changes

 static void Main(string args) 

to

 static void Main(string[] args) 

You may get the same error if you declared your "Basic" of any type except "void" or "int"

therefore, the signature of the "Main" method should always 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) 
+3
source

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

+1
source

All Articles