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
类型的内容: