3

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!

Community
  • 1
  • 1
Wes
  • 1,183
  • 3
  • 23
  • 51

1 Answers1

2

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.

Paul Suart
  • 6,505
  • 7
  • 44
  • 65
Wes
  • 1,183
  • 3
  • 23
  • 51