Data type conversion-Help

  • Thread starter Thread starter Badri Mohan
  • Start date Start date
B

Badri Mohan

Hi Guys

I am tired of finding solution to this..
Help me when u find time

How to convert from


int[] to byte[] //right now i do by a for loop
byte[] to int[] //right now i do by a for loop
int[] to string //I donno how to do this
string to int[] //I donno how to do this

Regards
Badri
 
Badri,

You can use the static Copy method on the Array class to do this.
However, it will not work in all cases. It will work for your second case
only. The reason it won't work for the others is as follows:

1 - You have the potential to lose information on the conversion of each
integer element to a byte element.
3 - The Copy method doesn't know how to convert between an int and a string.
You have to loop through each element and do the conversion yourself.
4 - The same as #3, but vice versa.

Hope this helps.
 
Thanks Nicholas..

Nicholas Paldino said:
Badri,

You can use the static Copy method on the Array class to do this.
However, it will not work in all cases. It will work for your second case
only. The reason it won't work for the others is as follows:

1 - You have the potential to lose information on the conversion of each
integer element to a byte element.
3 - The Copy method doesn't know how to convert between an int and a string.
You have to loop through each element and do the conversion yourself.
4 - The same as #3, but vice versa.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Badri Mohan said:
Hi Guys

I am tired of finding solution to this..
Help me when u find time

How to convert from


int[] to byte[] //right now i do by a for loop
byte[] to int[] //right now i do by a for loop
int[] to string //I donno how to do this
string to int[] //I donno how to do this

Regards
Badri
 
Back
Top