gpt4 book ai didi

ado.net - 在 f# 匹配语句中,如何匹配字节 [] 类型?

转载 作者:行者123 更新时间:2023-12-01 06:07:00 25 4
gpt4 key购买 nike

我正在尝试从 .net 类型中查找 DbType 枚举值。我正在使用匹配语句。但是我无法弄清楚如何匹配类型字节 []。

let dbType x =
match x with
| :? Int64 -> DbType.Int64
| :? Byte[] -> DbType.Binary // this gives an error
| _ -> DbType.Object

如果有更好的方法来映射这些类型,我愿意接受建议。

最佳答案

byte[] , byte array , 和 array<byte>都是同义词,但在这种情况下,只有最后一个可以不带括号:

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

关于ado.net - 在 f# 匹配语句中,如何匹配字节 [] 类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37348775/

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