Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
F# 将文本强制转换为F中的字节#_F#_Casting - Fatal编程技术网

F# 将文本强制转换为F中的字节#

F# 将文本强制转换为F中的字节#,f#,casting,F#,Casting,这是我的代码片段: let targetMeasure (usesPercent:Nullable<byte>) value = match usesPercent.Value with | 0 -> sprintf "$%A" value | _ -> sprintf "%A%%" value 让targetMeasure(usesPercent:Nullable)值= 将usesPercent.

这是我的代码片段:

let targetMeasure (usesPercent:Nullable<byte>) value =
            match usesPercent.Value with
            | 0 -> sprintf "$%A" value
            | _ -> sprintf "%A%%" value
让targetMeasure(usesPercent:Nullable)值=
将usesPercent.Value与匹配
|0->sprintf“$%A”值
|->sprintf“%A%%”值

正在尝试将“usesPercent”与0匹配,但0必须是一个字节。这总是让我在F#中感到困惑。我跳过了可为null的内容,但是值的类型不同。如何解决这个问题?

您可以通过编写
0uy
来创建字节文字。如果您编写了一些无效的数字文字(例如
0z
),F#Interactive将打印一个完整的数字文字列表。然后你会得到:

样本格式包括4、0x4、0b0100、4L、4UL、4u、4s、4us、4y、4uy、4.0、4.0f、4I

对于整数,很容易解码
u
代表无符号和
y
s
,(无),
L
分别代表8位、16位、32位和64位。

让targetMeasure(usesPercent:Nullable)值=
let targetMeasure (usesPercent:Nullable<byte>) value =
    match usesPercent.Value with
    | 0uy -> sprintf "$%A" value
    | _ -> sprintf "%A%%" value
将usesPercent.Value与匹配 |0uy->sprintf“$%A”值 |->sprintf“%A%%”值
另请参见文档中的“文字”,其中显示了所有
0uy
类型的内容: