Alex Rivera | Logout

Why can't I convert an object (which is really object[]) to string[]?

Asked 2012-04-13T14:07:18.067
8

I have a field that is of type 'object'. When I inspect it within the Watch window of visual studio I see its Object[] and when I drill into the elements I see each element is a string.

But when I try to cast this to a String[] I get this error:

Cannot cast 'MyObject' (which has an actual type of 'object[]') to 'string[]' string[]

Any reason why I can't do this cast? What is the best way to convert this object to a string array?

Edit
Report

1 Answer

-1

You can convert the real string[] to object[].

This is a Array covariance

Can find a clear example in link.

answered 2012-04-13T14:12:16.037

Your Answer