Archive for August, 2007

Convert a int[] to string[]

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(); 
}