Tuesday, October 18, 2011

unbox and data conversion

As a C# programmer, I was expect something like

object a = 123;
ulong b = (ulong)a;

should also work on F#. in order to make this work on F#, you need another operator "unbox"

let (a:int) = 123;
let (b:obj) = box(a)   //make the b as an object
let c = uint64(unbox(b)) //unbox b first and then you can convert

No comments: