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?
 
Back
Top