gpt4 book ai didi

c# - 使用 CommandLine lib 解析选项时出现错误的默认值异常

转载 作者:太空宇宙 更新时间:2023-11-03 23:12:15 25 4
gpt4 key购买 nike

我已经使用 CommandLine 库来解析它通过字符串类型、int 类型、bool 类型但它不能通过字节类型,我有一个异常 “Bad default value.”

    [Option("m", null, DefaultValue = 0, HelpText = "help")]
public byte mm { get; set; }

为什么会出现此异常以及如何解决?

最佳答案

根据编译器默认值,文字 0 是一个 Int32。您需要指定一个 byte 来匹配属性的类型。

不幸的是there is no byte literal symbol在 C# 中,因此您需要显式转换它:

[Option("m", null, DefaultValue = (byte)0, HelpText = "help")]
public byte mm { get; set; }

关于c# - 使用 CommandLine lib 解析选项时出现错误的默认值异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38724066/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com