Setting default values for Main function's args Array

Adam D. Ruppe destructionator at gmail.com
Thu Jun 27 17:12:44 UTC 2019


On Thursday, 27 June 2019 at 17:05:05 UTC, Vaidas wrote:
> Is it possible to set the default values for the Main 
> function's arguments?

No, as far as the language is concerned, a value is always being 
passed from the operating system, so those default values would 
never trigger.

What you could do though is just check inside main:

void main(string[] args) {
    if(args.length <= 1) args = ["defaults", "here"];
}


Keep in mind that args[0] is almost always set to the name of the 
executable, so length == 0 is liekly never going to happen.


More information about the Digitalmars-d-learn mailing list