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!
Asked
Active
Viewed 1,871 times
1 Answers
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
-
3In this case, one may also the null-coalescing operator and write `repeat = v ?? 1`. – fuglede Aug 12 '16 at 10:32
-
1if you declare v as a string you will get "r" as value, consider that – Anwar Hossain Feb 18 '18 at 16:11