How to convert object to object[]
<p>I have an <code>object</code> whose value may be one of several array types like <code>int[]</code> or <code>string[]</code>, and I want to convert it to a <code>string[]</code>. My first attempt failed:</p>

<pre><code>void Do(object value)
{
    if (value.GetType().IsArray)
    {
        object[] array = (object[])value;
        string[] strings = Array.ConvertAll(array, item =&gt; item.ToString());
        // ...
    }
}
</code></pre>

<p>with the runtime error <code>Unable to cast object of type 'System.Int32[]' to type 'System.Object[]'</code>, which makes sense in retrospect since my <code>int[]</code> doesn't contain boxed integers.</p>

<p>After poking around I arrived at this working version:</p>

<pre><code>void Do(object value)
{
    if (value.GetType().IsArray)
    {
        object[] array = ((Array)value).Cast&lt;object&gt;().ToArray();
        string[] strings = Array.ConvertAll(array, item =&gt; item.ToString());
        // ...
    }
}
</code></pre>

<p>I guess this is OK, but it seems pretty convoluted. Anyone have a simpler way?</p>
