JonnyBoats
JonnyBoats

Reputation: 5187

How to convert int64 to Nullable<int64>

This code:

let mutable x : Nullable<int64> = new  Nullable<int64> 99L
let y : int64 = 88L
x <- y

produces this compile time error:

This expression was expected to have type Nullable but here has type int64

I understand the error, what I would like to know is what is the correct way (cast?) to assign the value in y (88) to x?

Upvotes: 2

Views: 937

Answers (1)

Jack P.
Jack P.

Reputation: 11525

Use the System.Nullable constructor; for example:

> 
let mutable x = System.Nullable (99L)
let y = 88L
x <- System.Nullable y;;

val mutable x : Nullable<int64> = 88L
val y : int64 = 88L
val it : unit = ()

Upvotes: 7

Related Questions