In the f # matching file, how can I match the byte type []?

I am trying to find the DbType enum values ​​from .net types. I use the match operator. However, I cannot understand how a match is with byte type [].

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 match these types, I will be open to suggestions.

+7
source share
1 answer

byte[] , byte array and array<byte> are synonyms, but in this context only the latter 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 
+10
source

All Articles