简体   繁体   English

使用NDesk.Options设置可选值

[英]Setting optional values using NDesk.Options

Using the accepted answer in Best way to parse command line arguments in C#? 使用最佳方式接受的答案来解析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? 作为你的例子,我怎么能只选择'r'或'repeat'选项取值而不要求它,如果没有提供值,如何设置默认值? 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. 如果未提供该值,则默认值为1。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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