I tried to run a small c# and java program (using VS and NetBeans not from the command line) and print the value of the args[0] but I got an IndexOutOfRangeException.
I know that the args is for passing in command line parameters but it is still in the main method any way, So how the program will run if there is no args parameter passed to it ?
I tried to run a small c# and java program (using VS and NetBeans
Share
If there are none ( because you didn’t specify them in your IDE ) the array will be empty ( not null, at least not in Java )
Yo avoid having your
IndexOutOfRangeExceptionyou’ll have to either don’t use the argument, or assign a default value and validate the args array length.For instance ( in Java )