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
Post a Comment