Convert a int[] to string[]

Date August 7, 2007 @ 1:44 pm in Microsoft.Net 2.0

This morning I needed to convert an array of integers to strings and I stumbled across this nice little Array.ConvertAll generics method. My example is quite simple, but this technique could be used for much more complicated explicit casting.

1
2
3
4
5
6
7
int[] values = new int[]{1,2,3,4,5}; 
string[] strValues = Array.ConvertAll(values, new Converter(IntToString)); 
.... 
public static string IntToString(int integer) 
{ 
  return integer.ToString(); 
}

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="">