Convert a string

  • Thread starter Thread starter AMP
  • Start date Start date
A

AMP

Hello,
I want to convert a string Array permanantly to a int Array.
Everywhere in my code I have to use Convert.ToInt32 to use the data. I
just want to change it once.
Thanks
Mike
 
AMP said:
I want to convert a string Array permanantly to a int Array.
Everywhere in my code I have to use Convert.ToInt32 to use the data. I
just want to change it once.

The array cannot change types on the fly. You wil have to allocate a new
int Array, convert all the strings from the string array into the int array,
and then deallocate the string array. The simplest, although maybe not the
prettiest way to write it, is a loop that converts each element:

string[] theStrings = ...;
int[] theInts new int[theStrings.Length];
for (int i=0; i<theStrings.Length; i++)
theInts=int.Parse(theStrings);
 
AMP said:
Hello,
I want to convert a string Array permanantly to a int Array.
Everywhere in my code I have to use Convert.ToInt32 to use the data. I
just want to change it once.
Thanks
Mike

If you're storing integers in the array, why not just declare it as an
int array?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top