Not a cast, really: the parameter tells ToArray what sort of array to
create. Shakir's solution
//define new string array with the size of object array
string [] strArray= new string [objArray.Length];
//loop it out and fill the values
for(int j=0;j<strArray.Length;j++)
{
strArray[j] = (string)objArray[j];
}
is more or less what ToArray() does internally, with the expected result if
some member of the array isn't a string (i.e. an exception).
"AC" <sp**@aNOSPAMMEconnell.com> wrote in message
news:eu**************@tk2msftngp13.phx.gbl...
Makes sense when yo usee the answer. Thanks John. Wasn't aware
..ToArray() took an optional parm on what to cast the array as.
-AC
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om... AC <sp**@aNOSPAMMEconnell.com> wrote: I've put some strings into a stack, and now I want to convert the
stack to an string based array. Here's what I'm trying to do (this
returns a cast error)
string[] results = (string)resultStack.ToArray();
I've tried casting it as a string, an array of strings... no luck.
ideas?
string[] results = (string[])resultStack.ToArray(typeof(string));
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too