cast an object to string array

  • Thread starter Thread starter toufik
  • Start date Start date
T

toufik

Hi,
I'm using a method (from an API) that return an object which is a string
array.
How can I casst it to get a string array?

Thanks.
 
toufik said:
I'm using a method (from an API) that return an object which is a string
array. How can I casst it to get a string array?

As long as the thing the method returns is really a string[], then this
should work:

object o = ApiMethodThatReturnsObject();

string[] s = (string[])o;
 
Or just:
string[] sa = (string[]) ApiMethod();

or

string[] sa = ApiMethod() as string[];
if ( sa == null )
Console.Writeline("object null or not string[].");

--
William Stacey, MVP
http://mvp.support.microsoft.com

MarkT said:
toufik said:
I'm using a method (from an API) that return an object which is a string
array. How can I casst it to get a string array?

As long as the thing the method returns is really a string[], then this
should work:

object o = ApiMethodThatReturnsObject();

string[] s = (string[])o;
 
Back
Top