Setting default values for Main function's args Array

Paul Backus snarwin at gmail.com
Thu Jun 27 17:22:36 UTC 2019


On Thursday, 27 June 2019 at 17:20:37 UTC, Paul Backus wrote:
> void main(string[] args)
> {
>     string[] defaultArgs = ["my", "default", "arguments"];
>     if (args.length == 0) {
>         args = defaultArgs;
>     }
>     // Process args...
> }

Correction: you should check for `args.length == 1`, since (as 
Adam points out) the name of the program will be passed as 
args[0].


More information about the Digitalmars-d-learn mailing list