let retVal =
if reader.Read() then
(reader.GetString(0), getBytesData reader 1, reader.GetDateTime(2))
else
null
F# don't allow null to returned
How can i have value return as a tuple or a null?
It is not that F# does not allow you to return null.
It is because then part and else part have different types.
You can use Option type.
let retVal =
if reader.Read() then
Some (reader.GetString(0), getBytesData reader 1, reader.GetDateTime(2))
else
None
when you use retVal
, you use pattern matching:
match retVal with
| Some v -> ...
| None -> // null case
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With