c# - Entry is throwing errors -


this question has answer here:

i have this:

static void main(string[] arg) 

and:

main("month"); 

but reason, gives error:

the best overloaded method match 'numbers.program.main(string[])' has invalid arguments

and

argument 1: cannot convert 'string' 'string[]'

how fix these?

the other answers correct (the compiler not let pass string argument method expecting string array), alternative approach change method signature of main method so:

static void main(params string[] arg) 

the params keyword allows arguments passed in separately instead of array. thus, following calls equivalent:

main("month"); main(new string[] {"month"}); 

incidentally -- while legal, not common call main method (your program's entry point) own program. depending on requirements, may want consider new method has single string argument, e.g.:

public static void mymethod(string s) {       // code }  // in main method mymethod("month"); 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -