title: How to convert System.Object that's really an int32[] to a double[]?
body: <p>I get data from a 3rd party API that just gives me back a System.Object, which I know to be a double[] under the covers.  And to deal with that return type, I have found the code below to work wonderfully.  However, I also get back some int[] arrays that are also masquerading as System.Object, specifically dates in the form YYYYMMDD (e.g. 20100310).</p>
  
  <p>The conversion to float fails, and it just says that the specified cast is not valid.  Does anyone out there know how to make this work for integers?</p>
  
  <pre><code>let oIsNull (obj : System.Object) = obj = null
  let oIsArray (obj : System.Object) = obj.GetType().IsArray
  
  let o2f (obj : System.Object) = 
      let mutable arr = [|Double.NaN|]
      if (oIsNull obj = false) &amp;&amp; (oIsArray obj = true) then
          let objArr = obj :?&gt; obj[]
          let u = objArr.GetUpperBound(0)
          let floatArr : float[] = Array.zeroCreate (u  + 1);
          for i in 0..u do 
              if objArr.[i] = null then
                  floatArr.[i] &lt;- Double.NaN
              else 
                  let t = objArr.[i].GetType() 
                  floatArr.[i] &lt;- objArr.[i] :?&gt; float 
              //else floatArr.[i] &lt;- float objArr.[i]
          arr &lt;- floatArr
      arr
  </code></pre>