简体   繁体   中英

Setting optional values using NDesk.Options

Using the accepted answer in Best way to parse command line arguments in C#? as your example, how can I make the 'r' or 'repeat' option only OPTIONALLY take a value and not REQUIRE it, and how can I set a default value if the value is not provided? Thanks!

Apparently you can do something like:

{ "r|repeat:", 
       "the number of {TIMES} to repeat the greeting.\n" + 
          "this must be an integer.",
        (int v) => repeat = v ?? 1 },

Where the default value is 1 if the value is not provided.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM