在 f# 匹配语句中,如何匹配字节 [] 类型? [英] in f# match statement how do I match to the type byte[]?
本文介绍了在 f# 匹配语句中,如何匹配字节 [] 类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从 .net 类型中查找 DbType 枚举值.我正在使用匹配语句.但是我不知道如何匹配 byte[] 类型.
I'm trying to lookup DbType enumeration values from .net types. I'm using a match statement. However I cannot figure out how to match on the type byte[].
let dbType x =
match x with
| :? Int64 -> DbType.Int64
| :? Byte[] -> DbType.Binary // this gives an error
| _ -> DbType.Object
如果有更好的方法来映射这些类型,我愿意接受建议.
If there is a better way to map these types, I would be open to suggestions.
推荐答案
byte[]
, byte array
, and array
都是同义词,但在这种情况下,只有最后一个可以不带括号:
byte[]
, byte array
, and array<byte>
are all synonymous, but in this context only the last will work without parentheses:
let dbType (x:obj) =
match x with
| :? (byte[]) -> DbType.Binary
| :? (byte array) -> DbType.Binary // equivalent to above
| :? array<byte> -> DbType.Binary // equivalent to above
| :? int64 -> DbType.Int64
| _ -> DbType.Object
这篇关于在 f# 匹配语句中,如何匹配字节 [] 类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文